...

Source file src/k8s.io/kubernetes/pkg/volume/util/metrics_test.go

Documentation: k8s.io/kubernetes/pkg/volume/util

     1  /*
     2  Copyright 2020 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 util
    18  
    19  import (
    20  	"fmt"
    21  	"testing"
    22  
    23  	v1 "k8s.io/api/core/v1"
    24  	"k8s.io/kubernetes/pkg/volume"
    25  )
    26  
    27  func TestGetFullQualifiedPluginNameForVolume(t *testing.T) {
    28  	var (
    29  		fakePluginName          = "kubernetes.io/fakePlugin"
    30  		fakeInlineCSIDriverName = "fake.inline.csi.driver"
    31  		fakeCSIDriverName       = "fake.csi.driver"
    32  	)
    33  
    34  	testCase := []struct {
    35  		name         string
    36  		pluginName   string
    37  		spec         *volume.Spec
    38  		wantFullName string
    39  	}{
    40  		{
    41  			name:         "get full qualified plugin name without volume spec",
    42  			pluginName:   fakePluginName,
    43  			spec:         nil,
    44  			wantFullName: fakePluginName,
    45  		},
    46  		{
    47  			name:         "get full qualified plugin name without using CSI plugin",
    48  			pluginName:   fakePluginName,
    49  			spec:         &volume.Spec{},
    50  			wantFullName: fakePluginName,
    51  		},
    52  		{
    53  			name:       "get full qualified plugin name with CSI ephemeral volume",
    54  			pluginName: fakePluginName,
    55  			spec: &volume.Spec{
    56  				Volume: &v1.Volume{
    57  					VolumeSource: v1.VolumeSource{
    58  						CSI: &v1.CSIVolumeSource{
    59  							Driver: fakeInlineCSIDriverName,
    60  						},
    61  					},
    62  				},
    63  			},
    64  			wantFullName: fmt.Sprintf("%s:%s", fakePluginName, fakeInlineCSIDriverName),
    65  		},
    66  		{
    67  			name:       "get full qualified plugin name with CSI PV",
    68  			pluginName: fakePluginName,
    69  			spec: &volume.Spec{
    70  				PersistentVolume: &v1.PersistentVolume{
    71  					Spec: v1.PersistentVolumeSpec{
    72  						PersistentVolumeSource: v1.PersistentVolumeSource{
    73  							CSI: &v1.CSIPersistentVolumeSource{
    74  								Driver: fakeCSIDriverName,
    75  							},
    76  						},
    77  					},
    78  				},
    79  			},
    80  			wantFullName: fmt.Sprintf("%s:%s", fakePluginName, fakeCSIDriverName),
    81  		},
    82  	}
    83  
    84  	for _, test := range testCase {
    85  		t.Run(test.name, func(t *testing.T) {
    86  			if fullPluginName := GetFullQualifiedPluginNameForVolume(test.pluginName, test.spec); fullPluginName != test.wantFullName {
    87  				t.Errorf("Case name: %s, GetFullQualifiedPluginNameForVolume, pluginName:%s, spec: %v, return:%s, want:%s", test.name, test.pluginName, test.spec, fullPluginName, test.wantFullName)
    88  			}
    89  		})
    90  	}
    91  }
    92  

View as plain text