Add support for downloading content
[multicloud/k8s.git] / src / k8splugin / internal / rb / profile_test.go
1 // +build unit
2
3 /*
4  * Copyright 2018 Intel Corporation, Inc
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 package rb
20
21 import (
22         "bytes"
23         "k8splugin/internal/db"
24         "reflect"
25         "sort"
26         "strings"
27         "testing"
28
29         pkgerrors "github.com/pkg/errors"
30 )
31
32 func TestCreateProfile(t *testing.T) {
33         testCases := []struct {
34                 label         string
35                 inp           Profile
36                 expectedError string
37                 mockdb        *db.MockDB
38                 expected      Profile
39         }{
40                 {
41                         label: "Create Resource Bundle Profile",
42                         inp: Profile{
43                                 UUID:              "123e4567-e89b-12d3-a456-426655440000",
44                                 RBDID:             "abcde123-e89b-8888-a456-986655447236",
45                                 Name:              "testresourcebundle",
46                                 Namespace:         "default",
47                                 KubernetesVersion: "1.12.3",
48                         },
49                         expected: Profile{
50                                 UUID:              "123e4567-e89b-12d3-a456-426655440000",
51                                 RBDID:             "abcde123-e89b-8888-a456-986655447236",
52                                 Name:              "testresourcebundle",
53                                 Namespace:         "default",
54                                 KubernetesVersion: "1.12.3",
55                         },
56                         expectedError: "",
57                         mockdb: &db.MockDB{
58                                 Items: map[string]map[string][]byte{
59                                         "abcde123-e89b-8888-a456-986655447236": {
60                                                 "metadata": []byte(
61                                                         "{\"name\":\"testresourcebundle\"," +
62                                                                 "\"namespace\":\"default\"," +
63                                                                 "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
64                                                                 "\"kubernetesversion\":\"1.12.3\"}"),
65                                         },
66                                 },
67                         },
68                 },
69                 {
70                         label:         "Failed Create Resource Bundle Profile",
71                         expectedError: "Error Creating Profile",
72                         mockdb: &db.MockDB{
73                                 Err: pkgerrors.New("Error Creating Profile"),
74                         },
75                 },
76         }
77
78         for _, testCase := range testCases {
79                 t.Run(testCase.label, func(t *testing.T) {
80                         db.DBconn = testCase.mockdb
81                         impl := NewProfileClient()
82                         got, err := impl.Create(testCase.inp)
83                         if err != nil {
84                                 if testCase.expectedError == "" {
85                                         t.Fatalf("Create returned an unexpected error %s", err)
86                                 }
87                                 if strings.Contains(err.Error(), testCase.expectedError) == false {
88                                         t.Fatalf("Create returned an unexpected error %s", err)
89                                 }
90                         } else {
91                                 if reflect.DeepEqual(testCase.expected, got) == false {
92                                         t.Errorf("Create Resource Bundle returned unexpected body: got %v;"+
93                                                 " expected %v", got, testCase.expected)
94                                 }
95                         }
96                 })
97         }
98 }
99
100 func TestListProfiles(t *testing.T) {
101
102         testCases := []struct {
103                 label         string
104                 expectedError string
105                 mockdb        *db.MockDB
106                 expected      []Profile
107         }{
108                 {
109                         label: "List Resource Bundle Profile",
110                         expected: []Profile{
111                                 {
112                                         UUID:              "123e4567-e89b-12d3-a456-426655440000",
113                                         RBDID:             "abcde123-e89b-8888-a456-986655447236",
114                                         Name:              "testresourcebundle",
115                                         Namespace:         "default",
116                                         KubernetesVersion: "1.12.3",
117                                 },
118                         },
119                         expectedError: "",
120                         mockdb: &db.MockDB{
121                                 Items: map[string]map[string][]byte{
122                                         "123e4567-e89b-12d3-a456-426655440000": {
123                                                 "metadata": []byte(
124                                                         "{\"name\":\"testresourcebundle\"," +
125                                                                 "\"namespace\":\"default\"," +
126                                                                 "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
127                                                                 "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
128                                                                 "\"kubernetesversion\":\"1.12.3\"}"),
129                                         },
130                                 },
131                         },
132                 },
133                 {
134                         label:         "List Error",
135                         expectedError: "DB Error",
136                         mockdb: &db.MockDB{
137                                 Err: pkgerrors.New("DB Error"),
138                         },
139                 },
140         }
141
142         for _, testCase := range testCases {
143                 t.Run(testCase.label, func(t *testing.T) {
144                         db.DBconn = testCase.mockdb
145                         impl := NewProfileClient()
146                         got, err := impl.List()
147                         if err != nil {
148                                 if testCase.expectedError == "" {
149                                         t.Fatalf("List returned an unexpected error %s", err)
150                                 }
151                                 if strings.Contains(err.Error(), testCase.expectedError) == false {
152                                         t.Fatalf("List returned an unexpected error %s", err)
153                                 }
154                         } else {
155                                 // Since the order of returned slice is not guaranteed
156                                 // Check both and return error if both don't match
157                                 sort.Slice(got, func(i, j int) bool {
158                                         return got[i].UUID < got[j].UUID
159                                 })
160                                 // Sort both as it is not expected that testCase.expected
161                                 // is sorted
162                                 sort.Slice(testCase.expected, func(i, j int) bool {
163                                         return testCase.expected[i].UUID < testCase.expected[j].UUID
164                                 })
165
166                                 if reflect.DeepEqual(testCase.expected, got) == false {
167                                         t.Errorf("List Resource Bundle returned unexpected body: got %v;"+
168                                                 " expected %v", got, testCase.expected)
169                                 }
170                         }
171                 })
172         }
173 }
174
175 func TestGetProfile(t *testing.T) {
176
177         testCases := []struct {
178                 label         string
179                 expectedError string
180                 mockdb        *db.MockDB
181                 inp           string
182                 expected      Profile
183         }{
184                 {
185                         label: "Get Resource Bundle Profile",
186                         inp:   "123e4567-e89b-12d3-a456-426655440000",
187                         expected: Profile{
188                                 UUID:              "123e4567-e89b-12d3-a456-426655440000",
189                                 RBDID:             "abcde123-e89b-8888-a456-986655447236",
190                                 Name:              "testresourcebundle",
191                                 Namespace:         "default",
192                                 KubernetesVersion: "1.12.3",
193                         },
194                         expectedError: "",
195                         mockdb: &db.MockDB{
196                                 Items: map[string]map[string][]byte{
197                                         "123e4567-e89b-12d3-a456-426655440000": {
198                                                 "metadata": []byte(
199                                                         "{\"name\":\"testresourcebundle\"," +
200                                                                 "\"namespace\":\"default\"," +
201                                                                 "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
202                                                                 "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
203                                                                 "\"kubernetesversion\":\"1.12.3\"}"),
204                                         },
205                                 },
206                         },
207                 },
208                 {
209                         label:         "Get Error",
210                         expectedError: "DB Error",
211                         mockdb: &db.MockDB{
212                                 Err: pkgerrors.New("DB Error"),
213                         },
214                 },
215         }
216
217         for _, testCase := range testCases {
218                 t.Run(testCase.label, func(t *testing.T) {
219                         db.DBconn = testCase.mockdb
220                         impl := NewProfileClient()
221                         got, err := impl.Get(testCase.inp)
222                         if err != nil {
223                                 if testCase.expectedError == "" {
224                                         t.Fatalf("Get returned an unexpected error %s", err)
225                                 }
226                                 if strings.Contains(err.Error(), testCase.expectedError) == false {
227                                         t.Fatalf("Get returned an unexpected error %s", err)
228                                 }
229                         } else {
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)
233                                 }
234                         }
235                 })
236         }
237 }
238
239 func TestDeleteProfile(t *testing.T) {
240
241         testCases := []struct {
242                 label         string
243                 inp           string
244                 expectedError string
245                 mockdb        *db.MockDB
246         }{
247                 {
248                         label:  "Delete Resource Bundle Profile",
249                         inp:    "123e4567-e89b-12d3-a456-426655440000",
250                         mockdb: &db.MockDB{},
251                 },
252                 {
253                         label:         "Delete Error",
254                         expectedError: "DB Error",
255                         mockdb: &db.MockDB{
256                                 Err: pkgerrors.New("DB Error"),
257                         },
258                 },
259         }
260
261         for _, testCase := range testCases {
262                 t.Run(testCase.label, func(t *testing.T) {
263                         db.DBconn = testCase.mockdb
264                         impl := NewProfileClient()
265                         err := impl.Delete(testCase.inp)
266                         if err != nil {
267                                 if testCase.expectedError == "" {
268                                         t.Fatalf("Delete returned an unexpected error %s", err)
269                                 }
270                                 if strings.Contains(err.Error(), testCase.expectedError) == false {
271                                         t.Fatalf("Delete returned an unexpected error %s", err)
272                                 }
273                         }
274                 })
275         }
276 }
277
278 func TestUploadProfile(t *testing.T) {
279         testCases := []struct {
280                 label         string
281                 inp           string
282                 content       []byte
283                 expectedError string
284                 mockdb        *db.MockDB
285         }{
286                 {
287                         label: "Upload Resource Bundle Profile",
288                         inp:   "123e4567-e89b-12d3-a456-426655440000",
289                         content: []byte{
290                                 0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
291                                 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
292                                 0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
293                                 0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
294                                 0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
295                                 0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
296                                 0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
297                                 0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
298                                 0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
299                                 0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
300                                 0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
301                                 0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
302                                 0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
303                                 0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
304                                 0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
305                                 0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
306                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307                                 0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
308                                 0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
309                         },
310                         mockdb: &db.MockDB{
311                                 Items: map[string]map[string][]byte{
312                                         "123e4567-e89b-12d3-a456-426655440000": {
313                                                 "metadata": []byte(
314                                                         "{\"name\":\"testresourcebundle\"," +
315                                                                 "\"namespace\":\"default\"," +
316                                                                 "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
317                                                                 "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
318                                                                 "\"kubernetesversion\":\"1.12.3\"}"),
319                                         },
320                                 },
321                         },
322                 },
323                 {
324                         label:         "Upload with an Invalid Resource Bundle Profile",
325                         inp:           "123e4567-e89b-12d3-a456-426655440000",
326                         expectedError: "Invalid Profile ID provided",
327                         content: []byte{
328                                 0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
329                                 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
330                                 0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
331                                 0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
332                                 0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
333                                 0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
334                                 0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
335                                 0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
336                                 0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
337                                 0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
338                                 0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
339                                 0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
340                                 0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
341                                 0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
342                                 0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
343                                 0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
344                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
345                                 0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
346                                 0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
347                         },
348                         mockdb: &db.MockDB{
349                                 Items: map[string]map[string][]byte{
350                                         "123e4567-e89b-12d3-a456-426655441111": {
351                                                 "metadata": []byte(
352                                                         "{\"name\":\"testresourcebundle\"," +
353                                                                 "\"namespace\":\"default\"," +
354                                                                 "\"uuid\":\"123e4567-e89b-12d3-a456-426655441111\"," +
355                                                                 "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
356                                                                 "\"kubernetesversion\":\"1.12.3\"}"),
357                                         },
358                                 },
359                         },
360                 },
361                 {
362                         label:         "Invalid File Format Error",
363                         inp:           "123e4567-e89b-12d3-a456-426655440000",
364                         expectedError: "Error in file format",
365                         content: []byte{
366                                 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
367                                 0x00, 0xff, 0xf2, 0x48, 0xcd,
368                         },
369                         mockdb: &db.MockDB{
370                                 Items: map[string]map[string][]byte{
371                                         "123e4567-e89b-12d3-a456-426655440000": {
372                                                 "metadata": []byte(
373                                                         "{\"name\":\"testresourcebundle\"," +
374                                                                 "\"namespace\":\"default\"," +
375                                                                 "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
376                                                                 "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
377                                                                 "\"kubernetesversion\":\"1.12.3\"}"),
378                                         },
379                                 },
380                         },
381                 },
382                 {
383                         label:         "Upload Error",
384                         expectedError: "DB Error",
385                         content: []byte{
386                                 0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
387                                 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
388                                 0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
389                                 0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
390                                 0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
391                                 0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
392                                 0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
393                                 0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
394                                 0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
395                                 0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
396                                 0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
397                                 0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
398                                 0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
399                                 0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
400                                 0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
401                                 0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
402                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
403                                 0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
404                                 0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
405                         },
406                         mockdb: &db.MockDB{
407                                 Err: pkgerrors.New("DB Error"),
408                         },
409                 },
410         }
411
412         for _, testCase := range testCases {
413                 t.Run(testCase.label, func(t *testing.T) {
414                         db.DBconn = testCase.mockdb
415                         impl := NewProfileClient()
416                         err := impl.Upload(testCase.inp, testCase.content)
417                         if err != nil {
418                                 if testCase.expectedError == "" {
419                                         t.Errorf("Upload returned an unexpected error %s", err)
420                                 }
421                                 if strings.Contains(err.Error(), testCase.expectedError) == false {
422                                         t.Errorf("Upload returned an unexpected error %s", err)
423                                 }
424                         }
425                 })
426         }
427 }
428
429 func TestDownloadProfile(t *testing.T) {
430         testCases := []struct {
431                 label         string
432                 inp           string
433                 expected      []byte
434                 expectedError string
435                 mockdb        *db.MockDB
436         }{
437                 {
438                         label: "Download Resource Bundle Profile",
439                         inp:   "123e4567-e89b-12d3-a456-426655440000",
440                         expected: []byte{
441                                 0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
442                                 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
443                                 0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
444                                 0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
445                                 0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
446                                 0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
447                                 0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
448                                 0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
449                                 0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
450                                 0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
451                                 0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
452                                 0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
453                                 0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
454                                 0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
455                                 0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
456                                 0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
457                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
458                                 0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
459                                 0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
460                         },
461                         mockdb: &db.MockDB{
462                                 Items: map[string]map[string][]byte{
463                                         "123e4567-e89b-12d3-a456-426655440000": {
464                                                 "metadata": []byte(
465                                                         "{\"name\":\"testresourcebundle\"," +
466                                                                 "\"namespace\":\"default\"," +
467                                                                 "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
468                                                                 "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
469                                                                 "\"kubernetesversion\":\"1.12.3\"}"),
470                                                 "content": []byte("H4sICLBr9FsAA3Rlc3QudGFyAO3OQQrCMBCF4aw9RU5" +
471                                                         "QEtLE40igAUtSC+2IHt9IEVwIpYtShP/bvGFmFk/SLI08Re3IVCG077Rn" +
472                                                         "b75zYZ2yztVV8N7XP9vWSWmzZ6mP+yxx0lrF7pJzjkN/Sz//1u5/6ppKG" +
473                                                         "R/jVLrT0VUAAAAAAAAAAAAAAAAAABu8ALXoSvkAKAAA"),
474                                         },
475                                 },
476                         },
477                 },
478                 {
479                         label:         "Download with an Invalid Resource Bundle Profile",
480                         inp:           "123e4567-e89b-12d3-a456-426655440000",
481                         expectedError: "Invalid Profile ID provided",
482                         mockdb: &db.MockDB{
483                                 Items: map[string]map[string][]byte{
484                                         "123e4567-e89b-12d3-a456-426655441111": {
485                                                 "metadata": []byte(
486                                                         "{\"name\":\"testresourcebundle\"," +
487                                                                 "\"uuid\":\"123e4567-e89b-12d3-a456-426655441111\"," +
488                                                                 "\"namespace\":\"default\"," +
489                                                                 "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
490                                                                 "\"kubernetesversion\":\"1.12.3\"}"),
491                                         },
492                                 },
493                         },
494                 },
495                 {
496                         label:         "Download Error",
497                         expectedError: "DB Error",
498                         inp:           "123e4567-e89b-12d3-a456-426655440000",
499                         mockdb: &db.MockDB{
500                                 Err: pkgerrors.New("DB Error"),
501                         },
502                 },
503         }
504
505         for _, testCase := range testCases {
506                 t.Run(testCase.label, func(t *testing.T) {
507                         db.DBconn = testCase.mockdb
508                         impl := NewProfileClient()
509                         data, err := impl.Download(testCase.inp)
510                         if err != nil {
511                                 if testCase.expectedError == "" {
512                                         t.Errorf("Download returned an unexpected error %s", err)
513                                 }
514                                 if strings.Contains(err.Error(), testCase.expectedError) == false {
515                                         t.Errorf("Download returned an unexpected error %s", err)
516                                 }
517                         } else {
518                                 if bytes.Equal(testCase.expected, data) == false {
519                                         t.Errorf("Download returned unexpected data: got %v - expected %v",
520                                                 data, testCase.expected)
521                                 }
522                         }
523                 })
524         }
525 }