4
4
"reflect"
5
5
"testing"
6
6
7
+ "github.com/go-test/deep"
7
8
"github.com/travelaudience/armador/internal/commands"
8
9
)
9
10
@@ -167,7 +168,6 @@ func TestChartList_processCharts(t *testing.T) {
167
168
Tmp : commands.TmpDirs {Root : "tp/tmp/" , Extracted : "tp/tmp/extracted" , Hold : "tp/tmp/hold" },
168
169
Cache : commands.CacheDirs {Root : "tp/cache/" , Charts : "tp/cache/charts" },
169
170
}
170
- filterDuplicates := make (map [string ]struct {})
171
171
cmd := commands.CmdMock {}
172
172
tests := []struct {
173
173
name string
@@ -184,46 +184,149 @@ func TestChartList_processCharts(t *testing.T) {
184
184
{
185
185
name : "no-dependecy" ,
186
186
charts : & ChartList {
187
- "first-chart" : Chart {Name : "first-chart" , Repo : "stable" , ChartPath : "../testData" },
188
- "secondchart" : Chart {Name : "secondchart" , Repo : "stable" , ChartPath : "../testData" },
187
+ "first-chart" : Chart {Name : "first-chart" , Repo : "stable" , ChartPath : "../testData" , Packaged : false },
188
+ "secondchart" : Chart {Name : "secondchart" , Repo : "stable" , ChartPath : "../testData" , Packaged : false },
189
189
},
190
190
expectedCharts : & ChartList {
191
- "first-chart" : Chart {Name : "first-chart" , Repo : "stable" , ChartPath : "../testData" },
192
- "secondchart" : Chart {Name : "secondchart" , Repo : "stable" , ChartPath : "../testData" },
191
+ "first-chart" : Chart {Name : "first-chart" , Repo : "stable" , ChartPath : "../testData" , Packaged : false },
192
+ "secondchart" : Chart {Name : "secondchart" , Repo : "stable" , ChartPath : "../testData" , Packaged : false },
193
193
},
194
194
wantErr : false ,
195
195
},
196
196
{
197
197
name : "simple-dependecy" ,
198
198
charts : & ChartList {
199
- "first-chart" : Chart {Name : "first-chart" , Repo : "stable" , ChartPath : "../testData" ,
200
- Dependencies : []Chart {Chart {Name : "first-dep" , Repo : "github" , PathToChart : "helm/first-dep" }},
199
+ "first-chart" : Chart {Name : "first-chart" , Repo : "stable" , ChartPath : "../testData" , Packaged : false ,
200
+ Dependencies : []Chart {Chart {Name : "first-dep" , Repo : "github" , PathToChart : "helm/first-dep" , Packaged : false }},
201
+ },
202
+ "secondchart" : Chart {Name : "secondchart" , Repo : "stable" , ChartPath : "../testData" , Packaged : false },
203
+ },
204
+ expectedCharts : & ChartList {
205
+ "first-chart" : Chart {Name : "first-chart" , Repo : "stable" , ChartPath : "../testData" , Packaged : false ,
206
+ Dependencies : []Chart {Chart {Name : "first-dep" , Repo : "github" , PathToChart : "helm/first-dep" , Packaged : false }},
207
+ },
208
+ "first-dep" : Chart {Name : "first-dep" , Repo : "github" , Packaged : false ,
209
+ ChartPath : "tp/cache/charts/first-dep/helm/first-dep" , PathToChart : "helm/first-dep" ,
210
+ },
211
+ "secondchart" : Chart {Name : "secondchart" , Repo : "stable" , ChartPath : "../testData" , Packaged : false },
212
+ },
213
+ wantErr : false ,
214
+ },
215
+ {
216
+ name : "non-packaged-dependecy" ,
217
+ charts : & ChartList {
218
+ "first-chart" : Chart {
219
+ Name : "first-chart" ,
220
+ Repo : "stable" ,
221
+ ChartPath : "../testData" ,
222
+ Dependencies : []Chart {Chart {Name : "first-dep" , Repo : "github" , Version : "1.0.0" , Packaged : false , PathToChart : "helm/first-dep" }},
223
+ Packaged : false ,
224
+ PathToChart : "helm/first-chart" ,
201
225
},
202
226
"secondchart" : Chart {Name : "secondchart" , Repo : "stable" , ChartPath : "../testData" },
203
227
},
204
228
expectedCharts : & ChartList {
205
- "first-chart" : Chart {Name : "first-chart" , Repo : "stable" , ChartPath : "../testData" ,
206
- Dependencies : []Chart {Chart {Name : "first-dep" , Repo : "github" , PathToChart : "helm/first-dep" }},
229
+ "first-chart" : Chart {
230
+ Name : "first-chart" ,
231
+ Repo : "stable" ,
232
+ ChartPath : "../testData" ,
233
+ Dependencies : []Chart {Chart {Name : "first-dep" , Repo : "github" , Version : "1.0.0" , Packaged : false , PathToChart : "helm/first-dep" }},
234
+ Packaged : false ,
235
+ PathToChart : "helm/first-chart" ,
207
236
},
208
- "first-dep" : Chart {Name : "first-dep" , Repo : "github" ,
209
- ChartPath : "tp/cache/charts/first-dep" , Packaged : false ,
237
+ "first-dep" : Chart {Name : "first-dep" , Repo : "github" , Version : "1.0.0" ,
238
+ ChartPath : "tp/cache/charts/first-dep/helm/first-dep " , Packaged : false , PathToChart : "helm/first-dep" ,
210
239
},
211
240
"secondchart" : Chart {Name : "secondchart" , Repo : "stable" , ChartPath : "../testData" },
212
241
},
213
242
wantErr : false ,
214
243
},
244
+ {
245
+ // TODO: Some of these charts should be changed to `packaged: true` once this will be fixed: https://github.com/travelaudience/armador/issues/19
246
+ name : "duplicate-dependecy" ,
247
+ charts : & ChartList {
248
+ "first-chart" : Chart {
249
+ Name : "first-chart" ,
250
+ Repo : "stable" ,
251
+ ChartPath : "../basic" ,
252
+ Dependencies : []Chart {
253
+ Chart {
254
+ Name : "second-chart" ,
255
+ Repo : "stable" ,
256
+ Packaged : false ,
257
+ },
258
+ Chart {
259
+ Name : "third-chart" ,
260
+ Repo : "stable" ,
261
+ Packaged : false ,
262
+ },
263
+ Chart {
264
+ Name : "dep-chart" ,
265
+ Repo : "incubator" ,
266
+ Packaged : false ,
267
+ },
268
+ },
269
+ Packaged : false ,
270
+ },
271
+ },
272
+ expectedCharts : & ChartList {
273
+ "dep-chart" : Chart {
274
+ Name : "dep-chart" ,
275
+ Repo : "incubator" ,
276
+ ChartPath : "tp/cache/charts/dep-chart" ,
277
+ Packaged : false ,
278
+ },
279
+ "first-chart" : Chart {
280
+ Name : "first-chart" ,
281
+ Repo : "stable" ,
282
+ ChartPath : "../basic" ,
283
+ Dependencies : []Chart {
284
+ Chart {
285
+ Name : "second-chart" ,
286
+ Repo : "stable" ,
287
+ Packaged : false ,
288
+ },
289
+ Chart {
290
+ Name : "third-chart" ,
291
+ Repo : "stable" ,
292
+ Packaged : false ,
293
+ },
294
+ Chart {
295
+ Name : "dep-chart" ,
296
+ Repo : "incubator" ,
297
+ Packaged : false ,
298
+ },
299
+ },
300
+ Packaged : false ,
301
+ },
302
+ "second-chart" : Chart {
303
+ Name : "second-chart" ,
304
+ Repo : "stable" ,
305
+ ChartPath : "tp/cache/charts/second-chart" ,
306
+ Packaged : false ,
307
+ },
308
+ "third-chart" : Chart {
309
+ Name : "third-chart" ,
310
+ Repo : "stable" ,
311
+ ChartPath : "tp/cache/charts/third-chart" ,
312
+ Packaged : false ,
313
+ },
314
+ },
315
+ wantErr : false ,
316
+ },
215
317
}
216
318
for _ , tt := range tests {
217
319
t .Run (tt .name , func (t * testing.T ) {
218
320
depList := tt .charts .flattenInitialChartsMap ()
321
+ filterDuplicates := make (map [string ]struct {})
219
322
err := tt .charts .processCharts (cmd , depList , dirs , filterDuplicates )
220
323
if err != nil && ! tt .wantErr {
221
324
t .Errorf ("unexpected test error for %s: %v" , tt .name , err )
222
325
} else if err == nil && tt .wantErr {
223
326
t .Errorf ("expected error, no error received for %s" , tt .name )
224
327
}
225
- if ! reflect . DeepEqual (tt .expectedCharts , tt .charts ) {
226
- t .Errorf ("%s test failed. \n Got: %v \n Expected: %v" , tt .name , tt .charts , tt .expectedCharts )
328
+ if diff := deep . Equal (tt .charts , tt .expectedCharts ); diff != nil {
329
+ t .Errorf ("%s test failed.\n Diff: %s \n Got: %v \n Expected: %v" , tt .name , diff , tt .charts , tt .expectedCharts )
227
330
}
228
331
229
332
})
0 commit comments