-
Notifications
You must be signed in to change notification settings - Fork 48
/
manager_test.go
62 lines (56 loc) · 1.36 KB
/
manager_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
package circuit
import (
"strings"
"testing"
)
func TestManager_Empty(t *testing.T) {
h := Manager{}
if h.GetCircuit("does_not_exist") != nil {
t.Error("found a circuit that does not exist")
}
}
func TestManager_Var(t *testing.T) {
h := Manager{}
c := h.MustCreateCircuit("hello-world", Config{})
if !strings.Contains(h.Var().String(), "hello-world") {
t.Error("Var() does not seem to work for hystrix", h.Var())
}
if !strings.Contains(c.Var().String(), "hello-world") {
t.Error("Var() does not seem to work for circuits")
}
}
func TestManager_AllCircuits(t *testing.T) {
h := Manager{}
c := h.MustCreateCircuit("hello-world", Config{})
if len(h.AllCircuits()) != 1 {
t.Error("unexpected number of circuits")
}
if h.AllCircuits()[0] != c {
t.Error("unexpected circuit")
}
}
func TestSimpleCreate(t *testing.T) {
h := Manager{}
c := h.MustCreateCircuit("hello-world", Config{})
if c.Name() != "hello-world" {
t.Error("unexpected name")
}
c = h.GetCircuit("hello-world")
if c.Name() != "hello-world" {
t.Error("unexpected name")
}
}
func TestDoubleCreate(t *testing.T) {
h := Manager{}
h.MustCreateCircuit("hello-world", Config{})
var foundErr interface{}
func() {
defer func() {
foundErr = recover()
}()
h.MustCreateCircuit("hello-world", Config{})
}()
if foundErr == nil {
t.Error("Expect panic when must creating twice")
}
}