-
Notifications
You must be signed in to change notification settings - Fork 6
/
facts_test.go
51 lines (38 loc) · 986 Bytes
/
facts_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
package scientist
import (
"testing"
"golang.org/x/net/context"
)
func emptyBehavior(ctx context.Context) (interface{}, error) {
return nil, nil
}
func TestControl(t *testing.T) {
f := NewFacts()
if c := f.Control(); c != nil {
t.Fatal("expected no control")
}
if err := f.Use(emptyBehavior); err != nil {
t.Fatal(err)
}
if c := f.Control(); c == nil {
t.Fatal("expected control, got nil")
}
if err := f.Use(emptyBehavior); !IsBehaviorExist(err) {
t.Fatal("expected duplicated behavior error, got nil")
}
}
func TestBehavior(t *testing.T) {
f := NewFacts()
if b := f.Behavior("try something"); b != nil {
t.Fatal("expected no behavior")
}
if err := f.Try("try something", emptyBehavior); err != nil {
t.Fatal(err)
}
if b := f.Behavior("try something"); b == nil {
t.Fatal("expected behavior, got nil")
}
if err := f.Try("try something", emptyBehavior); !IsBehaviorExist(err) {
t.Fatal("expected duplicated behavior error, got nil")
}
}