@@ -62,11 +62,19 @@ func TestGetAttributes(t *testing.T) {
62
62
63
63
func TestUpdateAttributes (t * testing.T ) {
64
64
65
+ nestedValue := map [string ]interface {}{
66
+ "key1.1" : map [string ]interface {}{
67
+ "key1.1.1" : "value1.1.1" ,
68
+ },
69
+ }
70
+
65
71
tests := []struct {
66
- name string
67
- devfilev2 * DevfileV2
68
- attributes attributes.Attributes
69
- wantErr bool
72
+ name string
73
+ devfilev2 * DevfileV2
74
+ key string
75
+ value interface {}
76
+ wantAttributes attributes.Attributes
77
+ wantErr bool
70
78
}{
71
79
{
72
80
name : "Schema 2.0.0 does not have attributes" ,
@@ -80,7 +88,25 @@ func TestUpdateAttributes(t *testing.T) {
80
88
wantErr : true ,
81
89
},
82
90
{
83
- name : "Schema 2.1.0 has attributes" ,
91
+ name : "Schema 2.1.0 has the top-level key attribute" ,
92
+ devfilev2 : & DevfileV2 {
93
+ v1alpha2.Devfile {
94
+ DevfileHeader : devfilepkg.DevfileHeader {
95
+ SchemaVersion : "2.1.0" ,
96
+ },
97
+ DevWorkspaceTemplateSpec : v1alpha2.DevWorkspaceTemplateSpec {
98
+ DevWorkspaceTemplateSpecContent : v1alpha2.DevWorkspaceTemplateSpecContent {
99
+ Attributes : attributes.Attributes {}.PutString ("key1" , "value1" ).PutString ("key2" , "value2" ),
100
+ },
101
+ },
102
+ },
103
+ },
104
+ key : "key1" ,
105
+ value : nestedValue ,
106
+ wantAttributes : attributes.Attributes {}.Put ("key1" , nestedValue , nil ).PutString ("key2" , "value2" ),
107
+ },
108
+ {
109
+ name : "Schema 2.1.0 does not have the top-level key attribute" ,
84
110
devfilev2 : & DevfileV2 {
85
111
v1alpha2.Devfile {
86
112
DevfileHeader : devfilepkg.DevfileHeader {
@@ -93,21 +119,24 @@ func TestUpdateAttributes(t *testing.T) {
93
119
},
94
120
},
95
121
},
96
- attributes : attributes.Attributes {}.PutString ("key3" , "value3" ),
122
+ key : "key_invalid" ,
123
+ value : nestedValue ,
124
+ wantErr : true ,
97
125
},
98
126
}
99
127
for _ , tt := range tests {
100
128
t .Run (tt .name , func (t * testing.T ) {
101
- err := tt .devfilev2 .UpdateAttributes (tt .attributes )
129
+ err := tt .devfilev2 .UpdateAttributes (tt .key , tt . value )
102
130
if tt .wantErr == (err == nil ) {
103
131
t .Errorf ("TestUpdateAttributes error - %v, wantErr %v" , err , tt .wantErr )
104
132
} else if err == nil {
105
133
attributes , err := tt .devfilev2 .GetAttributes ()
106
134
if err != nil {
107
- t .Errorf ("TestUpdateAttributes error2 - %+v" , err )
135
+ t .Errorf ("TestUpdateAttributes error - %+v" , err )
136
+ return
108
137
}
109
- if ! reflect .DeepEqual (attributes , tt .attributes ) {
110
- t .Errorf ("TestUpdateAttributes mismatch error - expected %+v, actual %+v" , tt .attributes , attributes )
138
+ if ! reflect .DeepEqual (attributes , tt .wantAttributes ) {
139
+ t .Errorf ("TestUpdateAttributes mismatch error - expected %+v, actual %+v" , tt .wantAttributes , attributes )
111
140
}
112
141
}
113
142
})
@@ -186,7 +215,8 @@ func TestAddAttributes(t *testing.T) {
186
215
} else if err == nil {
187
216
attributes , err := tt .devfilev2 .GetAttributes ()
188
217
if err != nil {
189
- t .Errorf ("TestAddAttributes error2 - %+v" , err )
218
+ t .Errorf ("TestAddAttributes error - %+v" , err )
219
+ return
190
220
}
191
221
if ! reflect .DeepEqual (attributes , tt .wantAttributes ) {
192
222
t .Errorf ("TestAddAttributes mismatch error - expected %+v, actual %+v" , tt .wantAttributes , attributes )
0 commit comments