@@ -10,8 +10,6 @@ import (
10
10
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
11
11
attributesPkg "github.com/devfile/api/v2/pkg/attributes"
12
12
"github.com/stretchr/testify/assert"
13
- "k8s.io/apimachinery/pkg/util/json"
14
- yamlMachinery "k8s.io/apimachinery/pkg/util/yaml"
15
13
"sigs.k8s.io/yaml"
16
14
)
17
15
@@ -163,7 +161,7 @@ func TestBasicToplevelOverriding(t *testing.T) {
163
161
assert .Equal (t , expected , result , "The two values should be the same." )
164
162
}
165
163
166
- func overridingPatchTest (original , patch , expected []byte , expectedError string ) func (t * testing.T ) {
164
+ func overridingPatchTest (original , patch []byte , expectedTemplate dw. DevWorkspaceTemplateSpecContent , expectedError string ) func (t * testing.T ) {
167
165
return func (t * testing.T ) {
168
166
result , err := OverrideDevWorkspaceTemplateSpecBytes (original , patch )
169
167
if err != nil {
@@ -175,25 +173,7 @@ func overridingPatchTest(original, patch, expected []byte, expectedError string)
175
173
return
176
174
}
177
175
178
- resultJson , err := json .Marshal (result )
179
- if err != nil {
180
- t .Error (err )
181
- }
182
- resultYaml , err := yaml .JSONToYAML (resultJson )
183
- if err != nil {
184
- t .Error (err )
185
- }
186
-
187
- expectedJson , err := yamlMachinery .ToJSON (expected )
188
- if err != nil {
189
- t .Error (err )
190
- }
191
- expectedYaml , err := yaml .JSONToYAML (expectedJson )
192
- if err != nil {
193
- t .Error (err )
194
- }
195
-
196
- assert .Equal (t , string (expectedYaml ), string (resultYaml ), "The two values should be the same." )
176
+ assert .Equal (t , & expectedTemplate , result , "The two values should be the same" )
197
177
}
198
178
}
199
179
@@ -215,7 +195,7 @@ func TestOverridingPatches(t *testing.T) {
215
195
t .Error (err )
216
196
return nil
217
197
}
218
- result := [] byte {}
198
+ var resultTemplate dw. DevWorkspaceTemplateSpecContent
219
199
resultError := ""
220
200
errorFile := filepath .Join (dirPath , "result-error.txt" )
221
201
if _ , err = os .Stat (errorFile ); err == nil {
@@ -226,15 +206,11 @@ func TestOverridingPatches(t *testing.T) {
226
206
}
227
207
resultError = string (resultErrorBytes )
228
208
} else {
229
- result , err = ioutil .ReadFile (filepath .Join (dirPath , "result.yaml" ))
230
- if err != nil {
231
- t .Error (err )
232
- return nil
233
- }
209
+ readFileToStruct (t , filepath .Join (dirPath , "result.yaml" ), & resultTemplate )
234
210
}
235
211
testName := filepath .Base (dirPath )
236
212
237
- t .Run (testName , overridingPatchTest (original , patch , result , resultError ))
213
+ t .Run (testName , overridingPatchTest (original , patch , resultTemplate , resultError ))
238
214
}
239
215
return nil
240
216
})
0 commit comments