forked from flomesh-io/osm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
105 lines (89 loc) · 3.05 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
102
103
104
105
package configurator
import (
"testing"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
fakeConfig "github.com/openservicemesh/osm/pkg/gen/client/config/clientset/versioned/fake"
"github.com/openservicemesh/osm/pkg/metricsstore"
configv1alpha2 "github.com/openservicemesh/osm/pkg/apis/config/v1alpha2"
)
const (
osmNamespace = "-test-osm-namespace-"
osmMeshConfigName = "-test-osm-mesh-config-"
)
func TestGetMeshConfig(t *testing.T) {
a := assert.New(t)
meshConfigClient := fakeConfig.NewSimpleClientset()
stop := make(chan struct{})
c := newConfigurator(meshConfigClient, stop, osmNamespace, osmMeshConfigName, nil)
// Returns empty MeshConfig if informer cache is empty
a.Equal(configv1alpha2.MeshConfig{}, c.getMeshConfig())
newObj := &configv1alpha2.MeshConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "config.openservicemesh.io",
Kind: "MeshConfig",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: osmNamespace,
Name: osmMeshConfigName,
},
}
err := c.cache.Add(newObj)
a.Nil(err)
a.Equal(*newObj, c.getMeshConfig())
}
type store struct {
cache.Store
}
func (s *store) GetByKey(_ string) (interface{}, bool, error) {
return nil, false, nil
}
func TestMetricsHandler(t *testing.T) {
a := assert.New(t)
c := &client{
cache: &store{},
meshConfigName: osmMeshConfigName,
}
handlers := c.metricsHandler()
metricsstore.DefaultMetricsStore.Start(metricsstore.DefaultMetricsStore.FeatureFlagEnabled)
// Adding the MeshConfig
handlers.OnAdd(&configv1alpha2.MeshConfig{
ObjectMeta: metav1.ObjectMeta{
Name: osmMeshConfigName,
},
Spec: configv1alpha2.MeshConfigSpec{
FeatureFlags: configv1alpha2.FeatureFlags{
EnableRetryPolicy: true,
},
},
})
a.True(metricsstore.DefaultMetricsStore.Contains(`osm_feature_flag_enabled{feature_flag="enableRetryPolicy"} 1` + "\n"))
a.True(metricsstore.DefaultMetricsStore.Contains(`osm_feature_flag_enabled{feature_flag="enableSnapshotCacheMode"} 0` + "\n"))
// Updating the MeshConfig
handlers.OnUpdate(nil, &configv1alpha2.MeshConfig{
ObjectMeta: metav1.ObjectMeta{
Name: osmMeshConfigName,
},
Spec: configv1alpha2.MeshConfigSpec{
FeatureFlags: configv1alpha2.FeatureFlags{
EnableSnapshotCacheMode: true,
},
},
})
a.True(metricsstore.DefaultMetricsStore.Contains(`osm_feature_flag_enabled{feature_flag="enableRetryPolicy"} 0` + "\n"))
a.True(metricsstore.DefaultMetricsStore.Contains(`osm_feature_flag_enabled{feature_flag="enableSnapshotCacheMode"} 1` + "\n"))
// Deleting the MeshConfig
handlers.OnDelete(&configv1alpha2.MeshConfig{
ObjectMeta: metav1.ObjectMeta{
Name: osmMeshConfigName,
},
Spec: configv1alpha2.MeshConfigSpec{
FeatureFlags: configv1alpha2.FeatureFlags{
EnableSnapshotCacheMode: true,
},
},
})
a.True(metricsstore.DefaultMetricsStore.Contains(`osm_feature_flag_enabled{feature_flag="enableRetryPolicy"} 0` + "\n"))
a.True(metricsstore.DefaultMetricsStore.Contains(`osm_feature_flag_enabled{feature_flag="enableSnapshotCacheMode"} 0` + "\n"))
}