package repositories_test import ( "database/sql" "go-cook/api/repositories" "log" "testing" "github.com/DATA-DOG/go-sqlmock" _ "github.com/glebarez/go-sqlite" ) func TestCanCreateNewUser(t *testing.T) { db, _, err := sqlmock.New() //db, err := sql.Open("sqlite", "../../gocook.db") if err != nil { log.Println("unable to open connection") t.FailNow() } defer db.Close() repo := repositories.NewUserRepository(db) updated, err := repo.Create("testing", "NotSecure") if err != nil { log.Println(err) t.FailNow() } log.Println(updated) } func TestCanFindUserInTable(t *testing.T) { db, err := sql.Open("sqlite", "../../gocook.db") if err != nil { log.Println("unable to open connection") t.FailNow() } defer db.Close() repo := repositories.NewUserRepository(db) user, err := repo.GetByName("testing") if err != nil { log.Println(err) t.FailNow() } log.Println(user) } func TestCheckUserHash (t *testing.T) { db, err := sql.Open("sqlite", "../../gocook.db") if err != nil { log.Println("unable to open connection") t.FailNow() } defer db.Close() repo := repositories.NewUserRepository(db) repo.CheckUserHash("testing", "NotSecure") }