-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentity_mutate_go1.18_test.go
48 lines (39 loc) · 1.04 KB
/
entity_mutate_go1.18_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
37
38
39
40
41
42
43
44
45
46
47
48
//go:build go1.18
// +build go1.18
package reltest
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEntityMutate_Insert(t *testing.T) {
var (
repo = NewEntityRepository[Book]()
result = Book{Title: "Golang for dummies"}
book = Book{ID: 1, Title: "Golang for dummies"}
)
repo.ExpectInsert().For(&result).Success()
assert.Nil(t, repo.Insert(context.TODO(), &result))
assert.Equal(t, book, result)
repo.AssertExpectations(t)
repo.ExpectInsert().For(&result).Success()
assert.NotPanics(t, func() {
repo.MustInsert(context.TODO(), &result)
assert.Equal(t, book, result)
})
repo.AssertExpectations(t)
}
func TestEntityMutate_Update(t *testing.T) {
var (
repo = NewEntityRepository[Book]()
result = Book{ID: 2, Title: "Golang for dummies"}
)
repo.ExpectUpdate().For(&result)
assert.Nil(t, repo.Update(context.TODO(), &result))
repo.AssertExpectations(t)
repo.ExpectUpdate().For(&result)
assert.NotPanics(t, func() {
repo.MustUpdate(context.TODO(), &result)
})
repo.AssertExpectations(t)
}