61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package repositories_test
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
"testing"
|
|
|
|
"git.jamestombleson.com/jtom38/go-cook/internal/repositories"
|
|
"git.jamestombleson.com/jtom38/go-cook/internal/domain"
|
|
|
|
"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", domain.ScopeRecipeRead)
|
|
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")
|
|
}
|