-
Notifications
You must be signed in to change notification settings - Fork 2
/
fixture_test.go
48 lines (37 loc) · 869 Bytes
/
fixture_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
package fixtures
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
type DummyFixture struct {
BaseFixture
DummyMember int
}
func (df *DummyFixture) SetUp(ctx context.Context) error {
df.DummyMember = 123
return nil
}
func (df *DummyFixture) TearDown(context.Context) error {
df.DummyMember = 0
return nil
}
func TestGetType(t *testing.T) {
f := DummyFixture{}
assert.Equal(t, "fixtures.BaseFixture", f.Type())
}
func TestFixtures(t *testing.T) {
ctx := context.Background()
fixtures := NewFixtures()
df := DummyFixture{}
df2 := DummyFixture{}
err := fixtures.Add(ctx, &df)
assert.Nil(t, err)
err = fixtures.AddByName(ctx, "foobar", &df2)
assert.Nil(t, err)
fixtures.SetUp(ctx)
f := fixtures.Get("foobar").(*DummyFixture)
assert.Equal(t, 123, f.DummyMember)
fixtures.TearDown(ctx)
assert.Equal(t, 0, f.DummyMember)
}