-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeds_test.go
executable file
·65 lines (56 loc) · 1.2 KB
/
seeds_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
54
55
56
57
58
59
60
61
62
63
64
65
package seedloader
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetSeed(t *testing.T) {
scenarios := []struct {
scenarioName string
packageName string
inputSeed string
expectedError error
}{
{
"Initialize Seeder",
"ms.fish",
"",
ErrInitializingSeeder,
},
{
"Correct Payload",
"github.com/borderlesshq/seedloader",
"user.json",
nil,
},
{
"Cannot Open File",
"github.com/borderlesshq/seedloader",
"non-existing",
ErrOpeningSeed,
},
}
type User struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
}
for _, scenario := range scenarios {
t.Run(scenario.scenarioName, func(t *testing.T) {
seeder, err := NewSeedLoader(scenario.packageName, "seeds")
if err != nil {
assert.Equal(t, err, scenario.expectedError)
return
}
b, err := seeder.GetSeed(scenario.inputSeed)
assert.Equal(t, err, scenario.expectedError)
if err == nil {
assert.NotNil(t, b)
assert.NotEmpty(t, b)
}
var user User
err = seeder.ParseSeed("user.json", &user)
assert.Nil(t, err)
assert.Equal(t, user.FirstName, "Borderless")
assert.Equal(t, user.LastName, "HQ Inc.")
})
}
}