|
| 1 | +/* |
| 2 | +Copyright 2024 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 app |
| 18 | + |
| 19 | +import ( |
| 20 | + "reflect" |
| 21 | + "sort" |
| 22 | + "testing" |
| 23 | + |
| 24 | + "k8s.io/klog/v2/ktesting" |
| 25 | + persistentvolumeconfig "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/config" |
| 26 | + "k8s.io/kubernetes/pkg/volume" |
| 27 | +) |
| 28 | + |
| 29 | +func checkPlugins(t *testing.T, got []volume.VolumePlugin, expected []string) { |
| 30 | + pluginNames := make([]string, len(got)) |
| 31 | + for i, p := range got { |
| 32 | + pluginNames[i] = p.GetPluginName() |
| 33 | + } |
| 34 | + sort.Strings(pluginNames) |
| 35 | + sort.Strings(expected) |
| 36 | + if !reflect.DeepEqual(pluginNames, expected) { |
| 37 | + t.Errorf("Expected %+v, got %+v", expected, pluginNames) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func TestProbeAttachableVolumePlugins(t *testing.T) { |
| 42 | + logger, _ := ktesting.NewTestContext(t) |
| 43 | + plugins, err := ProbeAttachableVolumePlugins(logger) |
| 44 | + if err != nil { |
| 45 | + t.Fatalf("ProbeAttachableVolumePlugins failed: %s", err) |
| 46 | + } |
| 47 | + checkPlugins(t, plugins, []string{"kubernetes.io/csi", "kubernetes.io/fc", "kubernetes.io/iscsi", "kubernetes.io/portworx-volume"}) |
| 48 | +} |
| 49 | + |
| 50 | +func TestProbeExpandableVolumePlugins(t *testing.T) { |
| 51 | + logger, _ := ktesting.NewTestContext(t) |
| 52 | + plugins, err := ProbeExpandableVolumePlugins(logger, getConfig()) |
| 53 | + if err != nil { |
| 54 | + t.Fatalf("TestProbeExpandableVolumePlugins failed: %s", err) |
| 55 | + } |
| 56 | + checkPlugins(t, plugins, []string{"kubernetes.io/fc", "kubernetes.io/portworx-volume"}) |
| 57 | +} |
| 58 | + |
| 59 | +func TestProbeControllerVolumePlugins(t *testing.T) { |
| 60 | + logger, _ := ktesting.NewTestContext(t) |
| 61 | + plugins, err := ProbeControllerVolumePlugins(logger, getConfig()) |
| 62 | + if err != nil { |
| 63 | + t.Fatalf("ProbeControllerVolumePlugins failed: %s", err) |
| 64 | + } |
| 65 | + checkPlugins(t, plugins, []string{"kubernetes.io/host-path", "kubernetes.io/nfs", "kubernetes.io/portworx-volume"}) |
| 66 | +} |
| 67 | + |
| 68 | +func getConfig() persistentvolumeconfig.VolumeConfiguration { |
| 69 | + return persistentvolumeconfig.VolumeConfiguration{ |
| 70 | + EnableHostPathProvisioning: true, |
| 71 | + EnableDynamicProvisioning: true, |
| 72 | + PersistentVolumeRecyclerConfiguration: persistentvolumeconfig.PersistentVolumeRecyclerConfiguration{ |
| 73 | + MaximumRetry: 5, |
| 74 | + MinimumTimeoutNFS: 30, |
| 75 | + PodTemplateFilePathNFS: "", |
| 76 | + IncrementTimeoutNFS: 10, |
| 77 | + PodTemplateFilePathHostPath: "", |
| 78 | + MinimumTimeoutHostPath: 30, |
| 79 | + IncrementTimeoutHostPath: 10, |
| 80 | + }, |
| 81 | + FlexVolumePluginDir: "", |
| 82 | + } |
| 83 | +} |
0 commit comments