1 package storage 2 3 import odolabels "github.com/redhat-developer/odo/pkg/labels" 4 5 func getStorageLabels(storageName, componentName, applicationName string) map[string]string { 6 labels := odolabels.GetLabels(componentName, applicationName, "", odolabels.ComponentDevMode, false) 7 odolabels.AddStorageInfo(labels, storageName, false) 8 return labels 9 } 10 11 /* 12 func TestPush(t *testing.T) { 13 localStorage0 := localConfigProvider.LocalStorage{ 14 Name: "storage-0", 15 Size: "1Gi", 16 Path: "/data", 17 Container: "runtime-0", 18 Ephemeral: util.GetBool(false), 19 } 20 localStorage1 := localConfigProvider.LocalStorage{ 21 Name: "storage-1", 22 Size: "5Gi", 23 Path: "/path", 24 Container: "runtime-1", 25 Ephemeral: util.GetBool(false), 26 } 27 localEphemeralStorage0 := localConfigProvider.LocalStorage{ 28 Name: "ephemeral-storage-0", 29 Size: "5Gi", 30 Path: "/path", 31 Container: "runtime-1", 32 Ephemeral: util.GetBool(true), 33 } 34 35 clusterStorage0 := NewStorageWithContainer("storage-0", "1Gi", "/data", "runtime-0", util.GetBool(false)) 36 clusterStorage1 := NewStorageWithContainer("storage-1", "5Gi", "/path", "runtime-1", util.GetBool(false)) 37 38 tests := []struct { 39 name string 40 returnedFromLocal []localConfigProvider.LocalStorage 41 returnedFromCluster StorageList 42 createdItems []localConfigProvider.LocalStorage 43 deletedItems []string 44 wantErr bool 45 wantEphemeralNames []string 46 }{ 47 { 48 name: "case 1: no storage in both local and cluster", 49 returnedFromLocal: []localConfigProvider.LocalStorage{}, 50 returnedFromCluster: StorageList{}, 51 wantEphemeralNames: []string{}, 52 }, 53 { 54 name: "case 2: two persistent storage in local and no on cluster", 55 returnedFromLocal: []localConfigProvider.LocalStorage{localStorage0, localStorage1}, 56 returnedFromCluster: StorageList{}, 57 createdItems: []localConfigProvider.LocalStorage{ 58 { 59 Name: "storage-0", 60 Size: "1Gi", 61 Path: "/data", 62 Container: "runtime-0", 63 Ephemeral: util.GetBool(false), 64 }, 65 { 66 Name: "storage-1", 67 Size: "5Gi", 68 Path: "/path", 69 Container: "runtime-1", 70 Ephemeral: util.GetBool(false), 71 }, 72 }, 73 wantEphemeralNames: []string{}, 74 }, 75 { 76 name: "case 3: 0 persistent storage in local and two on cluster", 77 returnedFromLocal: []localConfigProvider.LocalStorage{}, 78 returnedFromCluster: StorageList{ 79 Items: []Storage{clusterStorage0, clusterStorage1}, 80 }, 81 createdItems: []localConfigProvider.LocalStorage{}, 82 deletedItems: []string{"storage-0", "storage-1"}, 83 wantEphemeralNames: []string{}, 84 }, 85 { 86 name: "case 4: same two persistent storage in local and cluster", 87 returnedFromLocal: []localConfigProvider.LocalStorage{localStorage0, localStorage1}, 88 returnedFromCluster: StorageList{ 89 Items: []Storage{clusterStorage0, clusterStorage1}, 90 }, 91 createdItems: []localConfigProvider.LocalStorage{}, 92 deletedItems: []string{}, 93 wantEphemeralNames: []string{}, 94 }, 95 { 96 name: "case 5: two persistent storage in both local and cluster but two of them are different and the other two are same", 97 returnedFromLocal: []localConfigProvider.LocalStorage{localStorage0, 98 { 99 Name: "storage-1-1", 100 Size: "5Gi", 101 Path: "/path", 102 Container: "runtime-1", 103 Ephemeral: util.GetBool(false), 104 }, 105 }, 106 returnedFromCluster: StorageList{ 107 Items: []Storage{ 108 clusterStorage0, 109 clusterStorage1, 110 }, 111 }, 112 createdItems: []localConfigProvider.LocalStorage{ 113 { 114 Name: "storage-1-1", 115 Size: "5Gi", 116 Path: "/path", 117 Container: "runtime-1", 118 Ephemeral: util.GetBool(false), 119 }, 120 }, 121 deletedItems: []string{clusterStorage1.Name}, 122 wantEphemeralNames: []string{}, 123 }, 124 { 125 name: "case 6: spec mismatch", 126 returnedFromLocal: []localConfigProvider.LocalStorage{ 127 { 128 Name: "storage-1", 129 Size: "3Gi", 130 Path: "/path", 131 Container: "runtime-1", 132 Ephemeral: util.GetBool(false), 133 }, 134 }, 135 returnedFromCluster: StorageList{ 136 Items: []Storage{ 137 clusterStorage1, 138 }, 139 }, 140 createdItems: []localConfigProvider.LocalStorage{}, 141 deletedItems: []string{}, 142 wantErr: true, 143 wantEphemeralNames: []string{}, 144 }, 145 { 146 name: "case 7: only one PVC created for two storage with same name but on different containers", 147 returnedFromLocal: []localConfigProvider.LocalStorage{ 148 { 149 Name: "storage-0", 150 Size: "1Gi", 151 Path: "/data", 152 Container: "runtime-0", 153 Ephemeral: util.GetBool(false), 154 }, 155 { 156 Name: "storage-0", 157 Size: "1Gi", 158 Path: "/path", 159 Container: "runtime-1", 160 Ephemeral: util.GetBool(false), 161 }, 162 }, 163 returnedFromCluster: StorageList{}, 164 createdItems: []localConfigProvider.LocalStorage{ 165 { 166 Name: "storage-0", 167 Size: "1Gi", 168 Path: "/path", 169 Container: "runtime-1", 170 Ephemeral: util.GetBool(false), 171 }, 172 }, 173 wantEphemeralNames: []string{}, 174 }, 175 { 176 name: "case 8: only path spec mismatch", 177 returnedFromLocal: []localConfigProvider.LocalStorage{ 178 { 179 Name: "storage-1", 180 Size: "5Gi", 181 Path: "/data", 182 Container: "runtime-1", 183 Ephemeral: util.GetBool(false), 184 }, 185 }, 186 returnedFromCluster: StorageList{ 187 Items: []Storage{ 188 clusterStorage1, 189 }, 190 }, 191 wantEphemeralNames: []string{}, 192 }, 193 { 194 name: "case 9: only one PVC deleted for two storage with same name but on different containers", 195 returnedFromLocal: []localConfigProvider.LocalStorage{}, 196 returnedFromCluster: StorageList{ 197 Items: []Storage{ 198 NewStorageWithContainer("storage-0", "1Gi", "/data", "runtime-0", util.GetBool(false)), 199 NewStorageWithContainer("storage-0", "1Gi", "/data", "runtime-1", util.GetBool(false)), 200 }, 201 }, 202 deletedItems: []string{"storage-0"}, 203 wantEphemeralNames: []string{}, 204 }, 205 { 206 name: "case 10: one ephemeral storage in local, none in cluster", 207 returnedFromLocal: []localConfigProvider.LocalStorage{localEphemeralStorage0}, 208 returnedFromCluster: StorageList{}, 209 wantEphemeralNames: []string{"ephemeral-storage-0"}, 210 }, 211 { 212 name: "case 11: one persistent + one ephemeral storage in local and no on cluster", 213 returnedFromLocal: []localConfigProvider.LocalStorage{localStorage0, localEphemeralStorage0}, 214 returnedFromCluster: StorageList{}, 215 createdItems: []localConfigProvider.LocalStorage{ 216 { 217 Name: "storage-0", 218 Size: "1Gi", 219 Path: "/data", 220 Container: "runtime-0", 221 Ephemeral: util.GetBool(false), 222 }, 223 }, 224 wantEphemeralNames: []string{"ephemeral-storage-0"}, 225 }, 226 } 227 for _, tt := range tests { 228 t.Run(tt.name, func(t *testing.T) { 229 230 ctrl := gomock.NewController(t) 231 defer ctrl.Finish() 232 233 fakeStorageClient := NewMockClient(ctrl) 234 fakeLocalConfig := localConfigProvider.NewMockLocalConfigProvider(ctrl) 235 236 fakeStorageClient.EXPECT().List().Return(tt.returnedFromCluster, nil).AnyTimes() 237 fakeLocalConfig.EXPECT().ListStorage(gomock.Any()).Return(tt.returnedFromLocal, nil).AnyTimes() 238 239 convert := ConvertListLocalToMachine(tt.createdItems) 240 for i := range convert.Items { 241 fakeStorageClient.EXPECT().Create(convert.Items[i]).Return(nil).Times(1) 242 } 243 244 for i := range tt.deletedItems { 245 fakeStorageClient.EXPECT().Delete(tt.deletedItems[i]).Return(nil).Times(1) 246 } 247 248 ephemerals, err := Push(fakeStorageClient, parser.DevfileObj{}) // feloy:TODO 249 if (err != nil) != tt.wantErr { 250 t.Errorf("Push() error = %v, wantErr %v", err, tt.wantErr) 251 } 252 ephemeralKeys := make([]string, 0, len(ephemerals)) 253 for k := range ephemerals { 254 ephemeralKeys = append(ephemeralKeys, k) 255 } 256 if diff := cmp.Diff(tt.wantEphemeralNames, ephemeralKeys); diff != "" { 257 t.Errorf("Push() ephemeral names mismatch (-want +got):\n%s", diff) 258 } 259 }) 260 } 261 }*/ 262