...
1 package featureflag
2
3 import (
4 "os"
5 "testing"
6 )
7
8 func TestFeatureEnabled_UseWarehouse(t *testing.T) {
9 _, ok := os.LookupEnv("LD_KEY")
10 if !ok {
11 t.Skip("skipping ff test because LD_KEY not set")
12 }
13 enabled, err := FeatureEnabled("", false)
14 if err != nil {
15 t.Fatal(err)
16 }
17 if !enabled {
18 t.Fatal("expected flag to evaluate to true")
19 }
20 }
21
22 func TestFeatureEnabledForContext(t *testing.T) {
23 _, ok := os.LookupEnv("LD_KEY")
24 if !ok {
25 t.Skip("skipping ff test because LD_KEY not set")
26 }
27 tests := map[string]struct {
28 inputCtx Contextualizer
29 flag string
30 expect bool
31 }{
32 "BannerContext": {NewBannerContext("35479cbe-8b40-4327-908b-da9074541db6"), "", true},
33 "ClusterContext": {NewClusterContext("22ab2a9a-c02b-4445-8474-35d624f883cc"), "", true},
34 }
35
36 for name, tc := range tests {
37 t.Run(name, func(t *testing.T) {
38 enabled, err := FeatureEnabledForContext(tc.inputCtx, tc.flag, false)
39 if err != nil {
40 t.Fatal(err)
41 }
42 if enabled != tc.expect {
43 t.Fatalf("expected flag to evaluate to %v. actual: %v", tc.expect, enabled)
44 }
45 })
46 }
47 }
48
View as plain text