|
| 1 | +/* |
| 2 | +Copyright 2019 The OpenEBS Authors. |
| 3 | +
|
| 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 |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 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. |
| 15 | +
|
| 16 | +*/ |
| 17 | + |
| 18 | +package app |
| 19 | + |
| 20 | +import ( |
| 21 | + "reflect" |
| 22 | + "testing" |
| 23 | + |
| 24 | + corev1 "k8s.io/api/core/v1" |
| 25 | +) |
| 26 | + |
| 27 | +func TestGetImagePullSecrets(t *testing.T) { |
| 28 | + testCases := map[string]struct { |
| 29 | + value string |
| 30 | + expectedValue []corev1.LocalObjectReference |
| 31 | + }{ |
| 32 | + "empty variable": { |
| 33 | + value: "", |
| 34 | + expectedValue: []corev1.LocalObjectReference{}, |
| 35 | + }, |
| 36 | + "single value": { |
| 37 | + value: "image-pull-secret", |
| 38 | + expectedValue: []corev1.LocalObjectReference{{Name: "image-pull-secret"}}, |
| 39 | + }, |
| 40 | + "multiple value": { |
| 41 | + value: "image-pull-secret,secret-1", |
| 42 | + expectedValue: []corev1.LocalObjectReference{{Name: "image-pull-secret"}, {Name: "secret-1"}}, |
| 43 | + }, |
| 44 | + "whitespaces": { |
| 45 | + value: " ", |
| 46 | + expectedValue: []corev1.LocalObjectReference{}, |
| 47 | + }, |
| 48 | + "single value with whitespaces": { |
| 49 | + value: " docker-secret ", |
| 50 | + expectedValue: []corev1.LocalObjectReference{{Name: "docker-secret"}}, |
| 51 | + }, |
| 52 | + "multiple value with whitespaces": { |
| 53 | + value: " docker-secret, image-pull-secret ", |
| 54 | + expectedValue: []corev1.LocalObjectReference{{Name: "docker-secret"}, {Name: "image-pull-secret"}}, |
| 55 | + }, |
| 56 | + } |
| 57 | + for k, v := range testCases { |
| 58 | + v := v |
| 59 | + t.Run(k, func(t *testing.T) { |
| 60 | + actualValue := GetImagePullSecrets(v.value) |
| 61 | + if !reflect.DeepEqual(actualValue, v.expectedValue) { |
| 62 | + t.Errorf("expected %s got %s", v.expectedValue, actualValue) |
| 63 | + } |
| 64 | + }) |
| 65 | + } |
| 66 | +} |
0 commit comments