forked from Unleash/unleash-client-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunleash_test.go
66 lines (58 loc) · 1.67 KB
/
unleash_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 unleash_test
import (
"fmt"
"os"
"testing"
"time"
"github.com/Unleash/unleash-client-go/v3"
)
func Test_withVariants(t *testing.T) {
demoReader, err := os.Open("demo_app_toggles.json")
if err != nil {
t.Fail()
}
err = unleash.Initialize(
unleash.WithListener(&unleash.DebugListener{}),
unleash.WithAppName("my-application"),
unleash.WithRefreshInterval(5*time.Second),
unleash.WithMetricsInterval(5*time.Second),
unleash.WithStorage(&unleash.BootstrapStorage{Reader: demoReader}),
unleash.WithUrl("https://localhost:4242"),
)
if err != nil {
t.Fail()
}
feature := unleash.GetVariant("Demo")
fmt.Printf("feature is %v\n", feature)
if feature.Enabled == false {
t.Fatalf("Expected feature to be enabled")
}
if feature.Name != "small" && feature.Name != "medium" {
t.Fatalf("Expected one of the variant names")
}
if feature.Payload.Value != "35" && feature.Payload.Value != "55" {
t.Fatalf("Expected one of the variant payloads")
}
}
func Test_withVariantsAndANonExistingStrategyName(t *testing.T) {
demoReader, err := os.Open("demo_app_toggles.json")
if err != nil {
t.Fail()
}
err = unleash.Initialize(
unleash.WithListener(&unleash.DebugListener{}),
unleash.WithAppName("my-application"),
unleash.WithRefreshInterval(5*time.Second),
unleash.WithMetricsInterval(5*time.Second),
unleash.WithStorage(&unleash.BootstrapStorage{Reader: demoReader}),
unleash.WithUrl("https://localhost:4242"),
)
if err != nil {
t.Fail()
}
feature := unleash.GetVariant("AuditLog")
fmt.Printf("feature is %v\n", feature)
if feature.Enabled == true {
t.Fatalf("Expected feature to be disabled because Environment does not exist as strategy")
}
}