-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_test.go
53 lines (40 loc) · 1.16 KB
/
create_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
49
50
51
52
53
package mgorepo
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/Drafteame/mgorepo/clock"
ptesting "github.com/Drafteame/mgorepo/internal/testing"
)
func TestRepository_Create(t *testing.T) {
t.Parallel()
t.Run("success create", func(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
c := clock.NewTest(time.Now()).ForceUTC()
expected := testModel{
Identifier: "identifier",
}
repo := newTestRepository(d).SetClock(c)
model, err := repo.Create(context.Background(), expected)
assert.Nil(t, err)
assert.NotEmpty(t, model.ID)
ptesting.AssertDate(t, c.Now(), model.CreatedAt)
ptesting.AssertDate(t, c.Now(), model.UpdatedAt)
})
t.Run("success create with no timestamps", func(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
c := clock.NewTest(time.Now()).ForceUTC()
expected := testModel{
Identifier: "identifier",
}
repo := newTestRepository(d).SetClock(c).WithTimestamps(false)
model, err := repo.Create(context.Background(), expected)
assert.Nil(t, err)
assert.NotEmpty(t, model.ID)
ptesting.AssertEmptyDate(t, model.CreatedAt)
ptesting.AssertEmptyDate(t, model.UpdatedAt)
})
}