2 * Copyright 2018 Intel Corporation, Inc
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 "github.com/onap/multicloud-k8s/src/k8splugin/internal/db"
27 pkgerrors "github.com/pkg/errors"
30 func TestCreateDefinition(t *testing.T) {
31 testCases := []struct {
39 label: "Create Resource Bundle Definition",
41 RBName: "testresourcebundle",
43 Description: "testresourcebundle",
47 RBName: "testresourcebundle",
49 Description: "testresourcebundle",
56 label: "Failed Create Resource Bundle Definition",
57 expectedError: "Error Creating Definition",
59 Err: pkgerrors.New("Error Creating Definition"),
64 for _, testCase := range testCases {
65 t.Run(testCase.label, func(t *testing.T) {
66 db.DBconn = testCase.mockdb
67 impl := NewDefinitionClient()
68 got, err := impl.Create(testCase.inp)
70 if testCase.expectedError == "" {
71 t.Fatalf("Create returned an unexpected error %s", err)
73 if strings.Contains(err.Error(), testCase.expectedError) == false {
74 t.Fatalf("Create returned an unexpected error %s", err)
77 if reflect.DeepEqual(testCase.expected, got) == false {
78 t.Errorf("Create Resource Bundle returned unexpected body: got %v;"+
79 " expected %v", got, testCase.expected)
86 func TestListDefinition(t *testing.T) {
88 testCases := []struct {
96 label: "List Resource Bundle Definition",
97 name: "testresourcebundle",
98 expected: []Definition{
100 RBName: "testresourcebundle",
102 Description: "testresourcebundle",
103 ChartName: "testchart",
106 RBName: "testresourcebundle",
108 Description: "testresourcebundle_version2",
109 ChartName: "testchart",
114 Items: map[string]map[string][]byte{
115 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
116 "defmetadata": []byte(
117 "{\"rb-name\":\"testresourcebundle\"," +
118 "\"description\":\"testresourcebundle\"," +
119 "\"rb-version\":\"v1\"," +
120 "\"chart-name\":\"testchart\"}"),
122 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v2"}.String(): {
123 "defmetadata": []byte(
124 "{\"rb-name\":\"testresourcebundle\"," +
125 "\"description\":\"testresourcebundle_version2\"," +
126 "\"rb-version\":\"v2\"," +
127 "\"chart-name\":\"testchart\"}"),
134 expectedError: "DB Error",
136 Err: pkgerrors.New("DB Error"),
141 for _, testCase := range testCases {
142 t.Run(testCase.label, func(t *testing.T) {
143 db.DBconn = testCase.mockdb
144 impl := NewDefinitionClient()
145 got, err := impl.List(testCase.name)
147 if testCase.expectedError == "" {
148 t.Fatalf("List returned an unexpected error %s", err)
150 if strings.Contains(err.Error(), testCase.expectedError) == false {
151 t.Fatalf("List returned an unexpected error %s", err)
154 // Since the order of returned slice is not guaranteed
155 // Check both and return error if both don't match
156 sort.Slice(got, func(i, j int) bool {
157 return got[i].RBVersion < got[j].RBVersion
159 // Sort both as it is not expected that testCase.expected
161 sort.Slice(testCase.expected, func(i, j int) bool {
162 return testCase.expected[i].RBVersion < testCase.expected[j].RBVersion
165 if reflect.DeepEqual(testCase.expected, got) == false {
166 t.Errorf("List Resource Bundle returned unexpected body: got %v;"+
167 " expected %v", got, testCase.expected)
174 func TestGetDefinition(t *testing.T) {
176 testCases := []struct {
186 label: "Get Resource Bundle Definition",
187 name: "testresourcebundle",
189 expected: Definition{
190 RBName: "testresourcebundle",
192 Description: "testresourcebundle",
193 ChartName: "testchart",
197 Items: map[string]map[string][]byte{
198 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
199 "defmetadata": []byte(
200 "{\"rb-name\":\"testresourcebundle\"," +
201 "\"description\":\"testresourcebundle\"," +
202 "\"rb-version\":\"v1\"," +
203 "\"chart-name\":\"testchart\"}"),
210 expectedError: "DB Error",
212 Err: pkgerrors.New("DB Error"),
217 for _, testCase := range testCases {
218 t.Run(testCase.label, func(t *testing.T) {
219 db.DBconn = testCase.mockdb
220 impl := NewDefinitionClient()
221 got, err := impl.Get(testCase.name, testCase.version)
223 if testCase.expectedError == "" {
224 t.Fatalf("Get returned an unexpected error %s", err)
226 if strings.Contains(err.Error(), testCase.expectedError) == false {
227 t.Fatalf("Get returned an unexpected error %s", err)
230 if reflect.DeepEqual(testCase.expected, got) == false {
231 t.Errorf("Get Resource Bundle returned unexpected body: got %v;"+
232 " expected %v", got, testCase.expected)
239 func TestDeleteDefinition(t *testing.T) {
241 testCases := []struct {
249 label: "Delete Resource Bundle Definition",
250 name: "testresourcebundle",
252 mockdb: &db.MockDB{},
255 label: "Delete Error",
256 expectedError: "DB Error",
258 Err: pkgerrors.New("DB Error"),
263 for _, testCase := range testCases {
264 t.Run(testCase.label, func(t *testing.T) {
265 db.DBconn = testCase.mockdb
266 impl := NewDefinitionClient()
267 err := impl.Delete(testCase.name, testCase.version)
269 if testCase.expectedError == "" {
270 t.Fatalf("Delete returned an unexpected error %s", err)
272 if strings.Contains(err.Error(), testCase.expectedError) == false {
273 t.Fatalf("Delete returned an unexpected error %s", err)
280 func TestUploadDefinition(t *testing.T) {
281 testCases := []struct {
289 label: "Upload With Chart Name Detection",
290 name: "testresourcebundle",
292 //Binary format for testchart/Chart.yaml
294 0x1f, 0x8b, 0x08, 0x08, 0xb3, 0xeb, 0x86, 0x5c,
295 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x63, 0x68,
296 0x61, 0x72, 0x74, 0x2e, 0x74, 0x61, 0x72, 0x00,
297 0xed, 0xd2, 0x41, 0x4b, 0xc3, 0x30, 0x18, 0xc6,
298 0xf1, 0x9c, 0xfb, 0x29, 0xde, 0x4f, 0x50, 0x93,
299 0x36, 0x69, 0x60, 0x37, 0xd9, 0x45, 0xf0, 0xee,
300 0x55, 0xe2, 0x16, 0xb1, 0x74, 0xed, 0x46, 0x9a,
301 0x0d, 0xfc, 0xf6, 0xae, 0x83, 0x4d, 0x91, 0x89,
302 0x97, 0x0d, 0x91, 0xfd, 0x7f, 0x87, 0x84, 0x90,
303 0x90, 0xbc, 0xe1, 0x79, 0x73, 0x1c, 0xf3, 0xe2,
304 0x2d, 0xa4, 0x7c, 0xa7, 0xae, 0x46, 0xef, 0x79,
305 0xef, 0xa6, 0xd9, 0x78, 0xa7, 0xbf, 0xce, 0x47,
306 0xca, 0xd4, 0xd6, 0x1a, 0xd7, 0xb8, 0xa6, 0xb6,
307 0x4a, 0x1b, 0x5b, 0xbb, 0x4a, 0x89, 0xbb, 0x5e,
308 0x49, 0x9f, 0xb6, 0x63, 0x0e, 0x49, 0x44, 0x85,
309 0xe5, 0x73, 0xd7, 0x75, 0xa1, 0x6f, 0x87, 0x78,
310 0xf6, 0xdc, 0x6f, 0xfb, 0xff, 0x54, 0x3e, 0xe5,
311 0x3f, 0x9f, 0xc6, 0xf2, 0x3d, 0xf4, 0xab, 0x4b,
312 0xbf, 0x31, 0x05, 0xdc, 0x34, 0xf6, 0xc7, 0xfc,
313 0x4d, 0xe5, 0xbf, 0xe5, 0xdf, 0x54, 0xde, 0x2b,
314 0xd1, 0x97, 0x2e, 0xe4, 0x9c, 0x1b, 0xcf, 0x3f,
315 0x6c, 0xda, 0xa7, 0x98, 0xc6, 0x76, 0x3d, 0xcc,
316 0x64, 0x67, 0x8a, 0x65, 0x1c, 0x17, 0xa9, 0xdd,
317 0xe4, 0xc3, 0xfa, 0x5e, 0x1e, 0xe2, 0xaa, 0x97,
318 0x43, 0x7b, 0xc8, 0xeb, 0x3a, 0xc9, 0xe3, 0xf6,
319 0x25, 0xa6, 0x21, 0xee, 0x7b, 0xa6, 0x18, 0x42,
320 0x1f, 0x67, 0x72, 0xea, 0x9e, 0x62, 0x77, 0xbc,
321 0x44, 0x97, 0xa6, 0xd4, 0xc5, 0x5f, 0x7f, 0x0b,
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323 0x00, 0x00, 0x00, 0x00, 0xb8, 0x09, 0x1f, 0xae,
324 0x48, 0xfe, 0xe8, 0x00, 0x28, 0x00, 0x00,
327 Items: map[string]map[string][]byte{
328 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
329 "defmetadata": []byte(
330 "{\"rb-name\":\"testresourcebundle\"," +
331 "\"description\":\"testresourcebundle\"," +
332 "\"rb-version\":\"v1\"}"),
338 label: "Upload With Chart Name",
339 name: "testresourcebundle",
342 0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
343 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
344 0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
345 0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
346 0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
347 0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
348 0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
349 0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
350 0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
351 0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
352 0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
353 0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
354 0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
355 0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
356 0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
357 0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
358 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
359 0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
360 0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
363 Items: map[string]map[string][]byte{
364 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
365 "defmetadata": []byte(
366 "{\"rb-name\":\"testresourcebundle\"," +
367 "\"description\":\"testresourcebundle\"," +
368 "\"rb-version\":\"v1\"," +
369 "\"chart-name\":\"firewall\"}"),
375 label: "Upload Without Chart.yaml",
376 name: "testresourcebundle",
378 expectedError: "Unable to detect chart name",
380 0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
381 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
382 0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
383 0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
384 0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
385 0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
386 0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
387 0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
388 0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
389 0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
390 0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
391 0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
392 0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
393 0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
394 0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
395 0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
397 0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
398 0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
401 Items: map[string]map[string][]byte{
402 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
403 "defmetadata": []byte(
404 "{\"rb-name\":\"testresourcebundle\"," +
405 "\"description\":\"testresourcebundle\"," +
406 "\"rb-version\":\"v1\"," +
407 "\"chart-name\":\"firewall\"}"),
413 label: "Upload with an Invalid Resource Bundle Definition",
414 name: "testresourcebundle",
416 expectedError: "Invalid Definition ID provided",
418 0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
419 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
420 0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
421 0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
422 0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
423 0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
424 0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
425 0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
426 0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
427 0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
428 0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
429 0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
430 0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
431 0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
432 0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
433 0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
435 0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
436 0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
439 Items: map[string]map[string][]byte{
440 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
441 "defmetadata": []byte(
442 "{\"rb-name\":\"testresourcebundle\"," +
443 "\"description\":\"testresourcebundle\"," +
444 "\"rb-version\":\"v1\"," +
445 "\"chart-name\":\"firewall\"}"),
451 label: "Invalid File Format Error",
452 name: "testresourcebundle",
454 expectedError: "Error in file format",
456 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
457 0x00, 0xff, 0xf2, 0x48, 0xcd,
460 Items: map[string]map[string][]byte{
461 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
462 "defmetadata": []byte(
463 "{\"rb-name\":\"testresourcebundle\"," +
464 "\"description\":\"testresourcebundle\"," +
465 "\"rb-version\":\"v1\"," +
466 "\"chart-name\":\"firewall\"}"),
472 label: "Upload Error",
473 expectedError: "DB Error",
475 0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
476 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
477 0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
478 0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
479 0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
480 0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
481 0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
482 0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
483 0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
484 0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
485 0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
486 0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
487 0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
488 0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
489 0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
490 0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
491 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
492 0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
493 0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
496 Err: pkgerrors.New("DB Error"),
501 for _, testCase := range testCases {
502 t.Run(testCase.label, func(t *testing.T) {
503 db.DBconn = testCase.mockdb
504 impl := NewDefinitionClient()
505 err := impl.Upload(testCase.name, testCase.version, testCase.content)
507 if testCase.expectedError == "" {
508 t.Errorf("Upload returned an unexpected error %s", err)
510 if strings.Contains(err.Error(), testCase.expectedError) == false {
511 t.Errorf("Upload returned an unexpected error %s", err)
518 func TestDownloadDefinition(t *testing.T) {
519 testCases := []struct {
527 label: "Download Resource Bundle Definition",
528 name: "testresourcebundle",
531 0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
532 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
533 0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
534 0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
535 0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
536 0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
537 0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
538 0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
539 0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
540 0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
541 0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
542 0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
543 0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
544 0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
545 0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
546 0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
547 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
548 0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
549 0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
552 Items: map[string]map[string][]byte{
553 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
554 "defmetadata": []byte(
555 "{\"rb-name\":\"testresourcebundle\"," +
556 "\"description\":\"testresourcebundle\"," +
557 "\"rb-version\":\"v1\"," +
558 "\"chart-name\":\"firewall\"}"),
559 "defcontent": []byte("H4sICLBr9FsAA3Rlc3QudGFyAO3OQQrCMBCF4aw9RU5" +
560 "QEtLE40igAUtSC+2IHt9IEVwIpYtShP/bvGFmFk/SLI08Re3IVCG077Rn" +
561 "b75zYZ2yztVV8N7XP9vWSWmzZ6mP+yxx0lrF7pJzjkN/Sz//1u5/6ppKG" +
562 "R/jVLrT0VUAAAAAAAAAAAAAAAAAABu8ALXoSvkAKAAA"),
568 label: "Download with an Invalid Resource Bundle Definition",
569 name: "testresourcebundle",
571 expectedError: "Invalid Definition ID provided",
573 Items: map[string]map[string][]byte{
574 DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): {
575 "defmetadata": []byte(
576 "{\"rb-name\":\"testresourcebundle\"," +
577 "\"description\":\"testresourcebundle\"," +
578 "\"rb-version\":\"v1\"," +
579 "\"chart-name\":\"firewall\"}"),
585 label: "Download Error",
586 expectedError: "DB Error",
588 Err: pkgerrors.New("DB Error"),
593 for _, testCase := range testCases {
594 t.Run(testCase.label, func(t *testing.T) {
595 db.DBconn = testCase.mockdb
596 impl := NewDefinitionClient()
597 data, err := impl.Download(testCase.name, testCase.version)
599 if testCase.expectedError == "" {
600 t.Errorf("Download returned an unexpected error %s", err)
602 if strings.Contains(err.Error(), testCase.expectedError) == false {
603 t.Errorf("Download returned an unexpected error %s", err)
606 if bytes.Equal(testCase.expected, data) == false {
607 t.Errorf("Download returned unexpected data: got %v - expected %v",
608 data, testCase.expected)