csi_drivers_store_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package csi_test
  14. import (
  15. "reflect"
  16. "testing"
  17. "k8s.io/kubernetes/pkg/volume/csi"
  18. )
  19. func TestDriversStore(t *testing.T) {
  20. store := &csi.DriversStore{}
  21. someDriver := csi.Driver{}
  22. expectAbsent(t, store, "does-not-exist")
  23. store.Set("some-driver", someDriver)
  24. expectPresent(t, store, "some-driver", someDriver)
  25. store.Delete("some-driver")
  26. expectAbsent(t, store, "some-driver")
  27. store.Set("some-driver", someDriver)
  28. store.Clear()
  29. expectAbsent(t, store, "some-driver")
  30. }
  31. func expectPresent(t *testing.T, store *csi.DriversStore, name string, expected csi.Driver) {
  32. t.Helper()
  33. retrieved, ok := store.Get(name)
  34. if !ok {
  35. t.Fatalf("expected driver '%s' to exist", name)
  36. }
  37. if !reflect.DeepEqual(retrieved, expected) {
  38. t.Fatalf("expected driver '%s' to be equal to %v", name, expected)
  39. }
  40. }
  41. func expectAbsent(t *testing.T, store *csi.DriversStore, name string) {
  42. t.Helper()
  43. if _, ok := store.Get(name); ok {
  44. t.Fatalf("expected driver '%s' not to exist in store", name)
  45. }
  46. }