go-cook/api/repositories/users_test.go

58 lines
1.2 KiB
Go
Raw Normal View History

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)
2024-03-26 17:53:22 -07:00
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")
}