snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s
Some checks failed
build / build (push) Failing after 3s
This commit is contained in:
36
user/utils_test.go
Normal file
36
user/utils_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/traggo/server/model"
|
||||
"github.com/traggo/server/test"
|
||||
)
|
||||
|
||||
var (
|
||||
ponyPW = []byte{1}
|
||||
unicornPW = []byte{2}
|
||||
fakePassword = func(pw string, strength int) []byte {
|
||||
if pw == "pony" {
|
||||
return ponyPW
|
||||
} else if pw == "unicorn" {
|
||||
return unicornPW
|
||||
}
|
||||
panic("unknown pw")
|
||||
}
|
||||
)
|
||||
|
||||
func assertUserExist(t *testing.T, db *test.Database, expected model.User) {
|
||||
foundUser := new(model.User)
|
||||
find := db.Find(foundUser, expected.ID)
|
||||
require.Nil(t, find.Error)
|
||||
require.NotNil(t, foundUser)
|
||||
require.Equal(t, expected, *foundUser)
|
||||
}
|
||||
|
||||
func assertUserCount(t *testing.T, db *test.Database, expected int) {
|
||||
count := new(int)
|
||||
db.Model(new(model.User)).Count(count)
|
||||
require.Equal(t, expected, *count)
|
||||
}
|
||||
Reference in New Issue
Block a user