-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_find_test.go
36 lines (32 loc) · 973 Bytes
/
user_find_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package test
import (
"context"
"log"
"testing"
"github.com/fajarcandraaa/simple-golang-unit-testing/test/faker"
"github.com/fajarcandraaa/simple-golang-unit-testing/test/seeders"
"github.com/stretchr/testify/assert"
)
func TestFindUserByID(t *testing.T) {
ctx := context.Background()
err := refreshTable()
if err != nil {
log.Fatalf("Error user refreshing table %v\n", err)
}
s := userRepository()
_, err = seeders.SeedUser(server.DB)
if err != nil {
log.Fatalf("Error user refreshing table %v\n", err)
}
t.Run("if document body request fulfilled, it should not return an error", func(t *testing.T) {
fakeFindUser, err := s.FindUser(ctx, faker.UserID001)
assert.NoError(t, err)
assert.NotNil(t, fakeFindUser)
})
t.Run("if given invalid type UUID, it should return an error", func(t *testing.T) {
fakeUserID := "this is not uuid"
fakeFindUser, err := s.FindUser(ctx, fakeUserID)
assert.Error(t, err)
assert.Nil(t, fakeFindUser)
})
}