-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper_test.go
66 lines (51 loc) · 1.28 KB
/
helper_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
66
package facto_test
import (
"strings"
"testing"
"github.com/wawandco/facto"
)
func TestHelperNamedUUID(t *testing.T) {
h := &facto.Helper{Index: 1}
u := h.NamedUUID("something")
u2 := h.NamedUUID("something")
if u.String() != u2.String() {
t.Errorf("NamedUUIDs should be the same")
}
u3 := h.NamedUUID("something else")
if u.String() == u3.String() {
t.Errorf("Diferent named UUIDS should result in different values")
}
}
func TestHelperOneOf(t *testing.T) {
h := &facto.Helper{Index: 1}
t.Run("Strings", func(t *testing.T) {
options := []string{"a", "b", "c"}
s, ok := h.OneOf("a", "b", "c").(string)
if !ok {
t.Errorf("OneOf should return a string")
}
if strings.Contains(strings.Join(options, "|"), s) == false {
t.Errorf("OneOf should return one of the options")
}
})
t.Run("CustomType", func(t *testing.T) {
type Status string
var (
StatusOpen Status = "open"
StatusClosed Status = "closed"
)
s, ok := h.OneOf(StatusOpen, StatusClosed).(Status)
if !ok {
t.Errorf("OneOf should return a Status")
}
if s != StatusOpen && s != StatusClosed {
t.Errorf("OneOf should return one of the Status passed")
}
})
t.Run("Empty", func(t *testing.T) {
s := h.OneOf()
if s != nil {
t.Errorf("OneOf should return Nil")
}
})
}