-
Notifications
You must be signed in to change notification settings - Fork 9
/
pool_test.go
61 lines (52 loc) · 1.57 KB
/
pool_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
package faker_test
import (
"fmt"
"testing"
"github.com/pioz/faker"
"github.com/stretchr/testify/assert"
)
func ExampleGetData() {
faker.SetSeed(801)
faker.SetPool("address", "city", faker.Pool{"New York", "Rome"})
value, err := faker.GetData("address", "city")
if err != nil {
panic(err)
}
fmt.Println(value)
// Output: New York
}
func TestGetAndSetPool(t *testing.T) {
faker.SetSeed(802)
faker.SetPool("ns1", "grp1", faker.Pool{"foo", "bar"})
value, err := faker.GetData("ns1", "grp1")
assert.Nil(t, err)
t.Log(value)
assert.Equal(t, "foo", value)
faker.SetPool("ns2", "grp1", faker.Pool{"foo", "bar"})
value, err = faker.GetData("ns2", "grp1")
assert.Nil(t, err)
t.Log(value)
assert.Equal(t, "bar", value)
faker.SetPool("ns2", "grp2", faker.Pool{"foo", "bar"})
value, err = faker.GetData("ns2", "grp2")
assert.Nil(t, err)
t.Log(value)
assert.Equal(t, "foo", value)
faker.SetPoolGroup("ns3", faker.PoolGroup{"grp1": faker.Pool{"foo", "bar"}})
value, err = faker.GetData("ns3", "grp1")
assert.Nil(t, err)
t.Log(value)
assert.Equal(t, "bar", value)
}
func TestGetDataWithNamespaceError(t *testing.T) {
faker.SetPool("ns4", "grp1", faker.Pool{"foo", "bar"})
_, err := faker.GetData("not-exist", "grp1")
assert.NotNil(t, err)
assert.Equal(t, "the namespace 'not-exist' does not exist", err.Error())
}
func TestGetDataWithGroupError(t *testing.T) {
faker.SetPool("ns5", "grp1", faker.Pool{"foo", "bar"})
_, err := faker.GetData("ns5", "not-exist")
assert.NotNil(t, err)
assert.Equal(t, "the group 'not-exist' in namespace 'ns5' does not exist", err.Error())
}