Skip to content

Commit

Permalink
fix: a bug of the map assertion (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
healthjyk committed Jan 10, 2024
1 parent 5eb12a8 commit c7dfc82
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions pkg/modules/generators/workload/job_generator_test.go
Expand Up @@ -45,10 +45,10 @@ func TestNewJobGenerator(t *testing.T) {
expectedAppName := "test"
expectedJob := &workload.Job{}
expectedJobConfig := apiv1.GenericConfig{
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"workload-type": "Job",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"workload-type": "Job",
},
}
Expand All @@ -72,10 +72,10 @@ func TestNewJobGeneratorFunc(t *testing.T) {
expectedAppName := "test"
expectedJob := &workload.Job{}
expectedJobConfig := apiv1.GenericConfig{
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"workload-type": "Job",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"workload-type": "Job",
},
}
Expand Down Expand Up @@ -110,10 +110,10 @@ func TestJobGenerator_Generate(t *testing.T) {
expectedAppName: "test",
expectedJob: &workload.Job{},
expectedJobConfig: apiv1.GenericConfig{
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"workload-type": "Job",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"workload-type": "Job",
},
},
Expand Down
12 changes: 6 additions & 6 deletions pkg/modules/generators/workload/network/ports_generator_test.go
Expand Up @@ -87,10 +87,10 @@ func TestValidatePortConfig(t *testing.T) {
name: "valid port config",
portConfig: apiv1.GenericConfig{
"type": "alicloud",
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"kusionstack.io/control": "true",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
},
},
Expand Down Expand Up @@ -144,10 +144,10 @@ func TestCompletePort(t *testing.T) {
},
portConfig: apiv1.GenericConfig{
"type": "alicloud",
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"kusionstack.io/control": "true",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
},
},
Expand Down Expand Up @@ -262,10 +262,10 @@ func TestPortsGenerator_Generate(t *testing.T) {
},
portConfig: apiv1.GenericConfig{
"type": "alicloud",
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"kusionstack.io/control": "true",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
},
},
Expand Down
14 changes: 7 additions & 7 deletions pkg/modules/generators/workload/service_generator_test.go
Expand Up @@ -218,19 +218,19 @@ status: {}
},
serviceConfig: apiv1.GenericConfig{
"type": "CollaSet",
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"service-workload-type": "CollaSet",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"service-workload-type": "CollaSet",
},
},
portConfig: apiv1.GenericConfig{
"type": "alicloud",
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"kusionstack.io/control": "true",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
},
},
Expand Down Expand Up @@ -276,16 +276,16 @@ status: {}
},
serviceConfig: apiv1.GenericConfig{
"replicas": 4,
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"service-workload-type": "Deployment",
},
},
portConfig: apiv1.GenericConfig{
"type": "alicloud",
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"kusionstack.io/control": "true",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
},
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/modules/generators/workload/workload_generator_test.go
Expand Up @@ -151,10 +151,10 @@ func TestWorkloadGenerator_Generate(t *testing.T) {
},
"port": {
"type": "alicloud",
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"kusionstack.io/control": "true",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
},
},
Expand Down Expand Up @@ -392,11 +392,11 @@ func TestCompleteBaseWorkload(t *testing.T) {
},
},
config: apiv1.GenericConfig{
"labels": map[string]any{
"labels": apiv1.GenericConfig{
"k1": "v1-ws",
"k3": "v3-ws",
},
"annotations": map[string]any{
"annotations": apiv1.GenericConfig{
"k1": "v1-ws",
},
"replicas": 4,
Expand Down
2 changes: 1 addition & 1 deletion pkg/workspace/util.go
Expand Up @@ -247,7 +247,7 @@ func GetMapFromGenericConfig(config v1.GenericConfig, key string) (map[string]an
if !ok {
return nil, nil
}
m, ok := value.(map[string]any)
m, ok := value.(v1.GenericConfig)
if !ok {
return nil, fmt.Errorf("the value of %s is not map", key)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/workspace/util_test.go
Expand Up @@ -12,11 +12,11 @@ func mockGenericConfig() v1.GenericConfig {
return v1.GenericConfig{
"int_type_field": 2,
"string_type_field": "kusion",
"map_type_field": map[string]any{
"map_type_field": v1.GenericConfig{
"k1": "v1",
"k2": 2,
},
"string_map_type_field": map[string]any{
"string_map_type_field": v1.GenericConfig{
"k1": "v1",
"k2": "v2",
},
Expand Down

0 comments on commit c7dfc82

Please sign in to comment.