Fix: render addon application checkDeployClusters invalid (#5555)

* Fix: render addon application checkDeployClusters invalid

Signed-off-by: zhaohuihui <zhaohuihui_yewu@cmss.chinamobile.com>

* Feat: add getClusters test logic

Signed-off-by: zhaohuihui <zhaohuihui_yewu@cmss.chinamobile.com>

---------

Signed-off-by: zhaohuihui <zhaohuihui_yewu@cmss.chinamobile.com>
This commit is contained in:
zhaohuiweixiao
2023-03-06 19:36:59 +08:00
committed by GitHub
parent 91638eba65
commit 6fa0d98547
2 changed files with 46 additions and 1 deletions
+11 -1
View File
@@ -599,10 +599,20 @@ func getClusters(args map[string]interface{}) []string {
return nil
}
cc, ok := ccr.([]string)
if ok {
return cc
}
ccrslice, ok := ccr.([]interface{})
if !ok {
return nil
}
return cc
var ccstring []string
for _, c := range ccrslice {
if cstring, ok := c.(string); ok {
ccstring = append(ccstring, cstring)
}
}
return ccstring
}
// renderNeededNamespaceAsComps will convert namespace as app components to create namespace for managed clusters
+35
View File
@@ -298,6 +298,41 @@ func TestRenderK8sObjects(t *testing.T) {
assert.Equal(t, comp.Type, "k8s-objects")
}
func TestGetClusters(t *testing.T) {
// string array test
args := map[string]interface{}{
types.ClustersArg: []string{
"cluster1", "cluster2",
},
}
clusters := getClusters(args)
assert.Equal(t, clusters, []string{
"cluster1", "cluster2",
})
// interface array test
args1 := map[string]interface{}{
types.ClustersArg: []interface{}{
"cluster3", "cluster4",
},
}
clusters1 := getClusters(args1)
assert.Equal(t, clusters1, []string{
"cluster3", "cluster4",
})
// no cluster arg test
args2 := map[string]interface{}{
"anyargkey": "anyargvalue",
}
clusters2 := getClusters(args2)
assert.Nil(t, clusters2)
// other type test
args3 := map[string]interface{}{
types.ClustersArg: "cluster5",
}
clusters3 := getClusters(args3)
assert.Nil(t, clusters3)
}
func TestGetAddonStatus(t *testing.T) {
getFunc := test.MockGetFn(func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
switch key.Name {