-
Notifications
You must be signed in to change notification settings - Fork 10
/
client_test.go
101 lines (85 loc) · 3.11 KB
/
client_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package configurator
import (
"testing"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fakeConfig "github.com/flomesh-io/fsm/pkg/gen/client/config/clientset/versioned/fake"
"github.com/flomesh-io/fsm/pkg/k8s/informers"
"github.com/flomesh-io/fsm/pkg/metricsstore"
configv1alpha3 "github.com/flomesh-io/fsm/pkg/apis/config/v1alpha3"
)
const (
fsmNamespace = "-test-fsm-namespace-"
fsmMeshConfigName = "-test-fsm-mesh-config-"
)
func TestGetMeshConfig(t *testing.T) {
a := assert.New(t)
meshConfigClient := fakeConfig.NewSimpleClientset()
stop := make(chan struct{})
ic, err := informers.NewInformerCollection("fsm", stop, informers.WithConfigClient(meshConfigClient, fsmMeshConfigName, fsmNamespace))
a.Nil(err)
c := NewConfigurator(ic, fsmNamespace, fsmMeshConfigName, nil)
// Returns empty MeshConfig if informer cache is empty
a.Equal(configv1alpha3.MeshConfig{}, c.getMeshConfig())
newObj := &configv1alpha3.MeshConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "config.flomesh.io",
Kind: "MeshConfig",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: fsmNamespace,
Name: fsmMeshConfigName,
},
}
err = c.informers.Add(informers.InformerKeyMeshConfig, newObj, t)
a.Nil(err)
a.Equal(*newObj, c.getMeshConfig())
}
func TestMetricsHandler(t *testing.T) {
a := assert.New(t)
c := &Client{
meshConfigName: fsmMeshConfigName,
informers: &informers.InformerCollection{},
}
handlers := c.metricsHandler()
metricsstore.DefaultMetricsStore.Start(metricsstore.DefaultMetricsStore.FeatureFlagEnabled)
// Adding the MeshConfig
handlers.OnAdd(&configv1alpha3.MeshConfig{
ObjectMeta: metav1.ObjectMeta{
Name: fsmMeshConfigName,
},
Spec: configv1alpha3.MeshConfigSpec{
FeatureFlags: configv1alpha3.FeatureFlags{
EnableRetryPolicy: true,
},
},
}, false)
a.True(metricsstore.DefaultMetricsStore.Contains(`fsm_feature_flag_enabled{feature_flag="enableRetryPolicy"} 1` + "\n"))
a.True(metricsstore.DefaultMetricsStore.Contains(`fsm_feature_flag_enabled{feature_flag="enableSnapshotCacheMode"} 0` + "\n"))
// Updating the MeshConfig
handlers.OnUpdate(nil, &configv1alpha3.MeshConfig{
ObjectMeta: metav1.ObjectMeta{
Name: fsmMeshConfigName,
},
Spec: configv1alpha3.MeshConfigSpec{
FeatureFlags: configv1alpha3.FeatureFlags{
EnableSnapshotCacheMode: true,
},
},
})
a.True(metricsstore.DefaultMetricsStore.Contains(`fsm_feature_flag_enabled{feature_flag="enableRetryPolicy"} 0` + "\n"))
a.True(metricsstore.DefaultMetricsStore.Contains(`fsm_feature_flag_enabled{feature_flag="enableSnapshotCacheMode"} 1` + "\n"))
// Deleting the MeshConfig
handlers.OnDelete(&configv1alpha3.MeshConfig{
ObjectMeta: metav1.ObjectMeta{
Name: fsmMeshConfigName,
},
Spec: configv1alpha3.MeshConfigSpec{
FeatureFlags: configv1alpha3.FeatureFlags{
EnableSnapshotCacheMode: true,
},
},
})
a.True(metricsstore.DefaultMetricsStore.Contains(`fsm_feature_flag_enabled{feature_flag="enableRetryPolicy"} 0` + "\n"))
a.True(metricsstore.DefaultMetricsStore.Contains(`fsm_feature_flag_enabled{feature_flag="enableSnapshotCacheMode"} 0` + "\n"))
}