k8s.io/kubernetes@v1.29.3/pkg/volume/csi/csi_drivers_store_test.go (about) 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 csi_test 18 19 import ( 20 "reflect" 21 "testing" 22 23 "k8s.io/kubernetes/pkg/volume/csi" 24 ) 25 26 func TestDriversStore(t *testing.T) { 27 store := &csi.DriversStore{} 28 someDriver := csi.Driver{} 29 30 expectAbsent(t, store, "does-not-exist") 31 32 store.Set("some-driver", someDriver) 33 expectPresent(t, store, "some-driver", someDriver) 34 35 store.Delete("some-driver") 36 expectAbsent(t, store, "some-driver") 37 38 store.Set("some-driver", someDriver) 39 40 store.Clear() 41 expectAbsent(t, store, "some-driver") 42 } 43 44 func expectPresent(t *testing.T, store *csi.DriversStore, name string, expected csi.Driver) { 45 t.Helper() 46 47 retrieved, ok := store.Get(name) 48 49 if !ok { 50 t.Fatalf("expected driver '%s' to exist", name) 51 } 52 53 if !reflect.DeepEqual(retrieved, expected) { 54 t.Fatalf("expected driver '%s' to be equal to %v", name, expected) 55 } 56 } 57 58 func expectAbsent(t *testing.T, store *csi.DriversStore, name string) { 59 t.Helper() 60 61 if _, ok := store.Get(name); ok { 62 t.Fatalf("expected driver '%s' not to exist in store", name) 63 } 64 }