|
| 1 | +/* |
| 2 | +Copyright 2019 The Kubernetes 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 | +package plugins |
| 18 | + |
| 19 | +import ( |
| 20 | + "reflect" |
| 21 | + "testing" |
| 22 | + |
| 23 | + storage "k8s.io/api/storage/v1" |
| 24 | +) |
| 25 | + |
| 26 | +func NewStorageClass(params map[string]string) storage.StorageClass { |
| 27 | + return storage.StorageClass{ |
| 28 | + Parameters: params, |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +func TestTranslatePDInTreeVolumeOptionsToCSI(t *testing.T) { |
| 33 | + g := NewGCEPersistentDiskCSITranslator() |
| 34 | + |
| 35 | + tcs := []struct { |
| 36 | + name string |
| 37 | + options storage.StorageClass |
| 38 | + expOptions storage.StorageClass |
| 39 | + }{ |
| 40 | + { |
| 41 | + name: "nothing special", |
| 42 | + options: NewStorageClass(map[string]string{"foo": "bar"}), |
| 43 | + expOptions: NewStorageClass(map[string]string{"foo": "bar"}), |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "fstype", |
| 47 | + options: NewStorageClass(map[string]string{"fstype": "myfs"}), |
| 48 | + expOptions: NewStorageClass(map[string]string{"csi.storage.k8s.io/fstype": "myfs"}), |
| 49 | + }, |
| 50 | + { |
| 51 | + name: "empty params", |
| 52 | + options: NewStorageClass(map[string]string{}), |
| 53 | + expOptions: NewStorageClass(map[string]string{}), |
| 54 | + }, |
| 55 | + } |
| 56 | + |
| 57 | + for _, tc := range tcs { |
| 58 | + t.Logf("Testing %v", tc.name) |
| 59 | + gotOptions, err := g.TranslateInTreeVolumeOptionsToCSI(tc.options) |
| 60 | + if err != nil { |
| 61 | + t.Errorf("Did not expect error but got: %v", err) |
| 62 | + } |
| 63 | + if !reflect.DeepEqual(gotOptions, tc.expOptions) { |
| 64 | + t.Errorf("Got parameters: %v, expected :%v", gotOptions, tc.expOptions) |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments