Skip to content

Commit c7dfc82

Browse files
authored
fix: a bug of the map assertion (#743)
1 parent 5eb12a8 commit c7dfc82

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

pkg/modules/generators/workload/job_generator_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ func TestNewJobGenerator(t *testing.T) {
4545
expectedAppName := "test"
4646
expectedJob := &workload.Job{}
4747
expectedJobConfig := apiv1.GenericConfig{
48-
"labels": map[string]any{
48+
"labels": apiv1.GenericConfig{
4949
"workload-type": "Job",
5050
},
51-
"annotations": map[string]any{
51+
"annotations": apiv1.GenericConfig{
5252
"workload-type": "Job",
5353
},
5454
}
@@ -72,10 +72,10 @@ func TestNewJobGeneratorFunc(t *testing.T) {
7272
expectedAppName := "test"
7373
expectedJob := &workload.Job{}
7474
expectedJobConfig := apiv1.GenericConfig{
75-
"labels": map[string]any{
75+
"labels": apiv1.GenericConfig{
7676
"workload-type": "Job",
7777
},
78-
"annotations": map[string]any{
78+
"annotations": apiv1.GenericConfig{
7979
"workload-type": "Job",
8080
},
8181
}
@@ -110,10 +110,10 @@ func TestJobGenerator_Generate(t *testing.T) {
110110
expectedAppName: "test",
111111
expectedJob: &workload.Job{},
112112
expectedJobConfig: apiv1.GenericConfig{
113-
"labels": map[string]any{
113+
"labels": apiv1.GenericConfig{
114114
"workload-type": "Job",
115115
},
116-
"annotations": map[string]any{
116+
"annotations": apiv1.GenericConfig{
117117
"workload-type": "Job",
118118
},
119119
},

pkg/modules/generators/workload/network/ports_generator_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ func TestValidatePortConfig(t *testing.T) {
8787
name: "valid port config",
8888
portConfig: apiv1.GenericConfig{
8989
"type": "alicloud",
90-
"labels": map[string]any{
90+
"labels": apiv1.GenericConfig{
9191
"kusionstack.io/control": "true",
9292
},
93-
"annotations": map[string]any{
93+
"annotations": apiv1.GenericConfig{
9494
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
9595
},
9696
},
@@ -144,10 +144,10 @@ func TestCompletePort(t *testing.T) {
144144
},
145145
portConfig: apiv1.GenericConfig{
146146
"type": "alicloud",
147-
"labels": map[string]any{
147+
"labels": apiv1.GenericConfig{
148148
"kusionstack.io/control": "true",
149149
},
150-
"annotations": map[string]any{
150+
"annotations": apiv1.GenericConfig{
151151
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
152152
},
153153
},
@@ -262,10 +262,10 @@ func TestPortsGenerator_Generate(t *testing.T) {
262262
},
263263
portConfig: apiv1.GenericConfig{
264264
"type": "alicloud",
265-
"labels": map[string]any{
265+
"labels": apiv1.GenericConfig{
266266
"kusionstack.io/control": "true",
267267
},
268-
"annotations": map[string]any{
268+
"annotations": apiv1.GenericConfig{
269269
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
270270
},
271271
},

pkg/modules/generators/workload/service_generator_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,19 @@ status: {}
218218
},
219219
serviceConfig: apiv1.GenericConfig{
220220
"type": "CollaSet",
221-
"labels": map[string]any{
221+
"labels": apiv1.GenericConfig{
222222
"service-workload-type": "CollaSet",
223223
},
224-
"annotations": map[string]any{
224+
"annotations": apiv1.GenericConfig{
225225
"service-workload-type": "CollaSet",
226226
},
227227
},
228228
portConfig: apiv1.GenericConfig{
229229
"type": "alicloud",
230-
"labels": map[string]any{
230+
"labels": apiv1.GenericConfig{
231231
"kusionstack.io/control": "true",
232232
},
233-
"annotations": map[string]any{
233+
"annotations": apiv1.GenericConfig{
234234
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
235235
},
236236
},
@@ -276,16 +276,16 @@ status: {}
276276
},
277277
serviceConfig: apiv1.GenericConfig{
278278
"replicas": 4,
279-
"labels": map[string]any{
279+
"labels": apiv1.GenericConfig{
280280
"service-workload-type": "Deployment",
281281
},
282282
},
283283
portConfig: apiv1.GenericConfig{
284284
"type": "alicloud",
285-
"labels": map[string]any{
285+
"labels": apiv1.GenericConfig{
286286
"kusionstack.io/control": "true",
287287
},
288-
"annotations": map[string]any{
288+
"annotations": apiv1.GenericConfig{
289289
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
290290
},
291291
},

pkg/modules/generators/workload/workload_generator_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ func TestWorkloadGenerator_Generate(t *testing.T) {
151151
},
152152
"port": {
153153
"type": "alicloud",
154-
"labels": map[string]any{
154+
"labels": apiv1.GenericConfig{
155155
"kusionstack.io/control": "true",
156156
},
157-
"annotations": map[string]any{
157+
"annotations": apiv1.GenericConfig{
158158
"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec": "slb.s1.small",
159159
},
160160
},
@@ -392,11 +392,11 @@ func TestCompleteBaseWorkload(t *testing.T) {
392392
},
393393
},
394394
config: apiv1.GenericConfig{
395-
"labels": map[string]any{
395+
"labels": apiv1.GenericConfig{
396396
"k1": "v1-ws",
397397
"k3": "v3-ws",
398398
},
399-
"annotations": map[string]any{
399+
"annotations": apiv1.GenericConfig{
400400
"k1": "v1-ws",
401401
},
402402
"replicas": 4,

pkg/workspace/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func GetMapFromGenericConfig(config v1.GenericConfig, key string) (map[string]an
247247
if !ok {
248248
return nil, nil
249249
}
250-
m, ok := value.(map[string]any)
250+
m, ok := value.(v1.GenericConfig)
251251
if !ok {
252252
return nil, fmt.Errorf("the value of %s is not map", key)
253253
}

pkg/workspace/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ func mockGenericConfig() v1.GenericConfig {
1212
return v1.GenericConfig{
1313
"int_type_field": 2,
1414
"string_type_field": "kusion",
15-
"map_type_field": map[string]any{
15+
"map_type_field": v1.GenericConfig{
1616
"k1": "v1",
1717
"k2": 2,
1818
},
19-
"string_map_type_field": map[string]any{
19+
"string_map_type_field": v1.GenericConfig{
2020
"k1": "v1",
2121
"k2": "v2",
2222
},

0 commit comments

Comments
 (0)