1// +build !providerless 2 3/* 4Copyright 2015 The Kubernetes Authors. 5 6Licensed under the Apache License, Version 2.0 (the "License"); 7you may not use this file except in compliance with the License. 8You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12Unless required by applicable law or agreed to in writing, software 13distributed under the License is distributed on an "AS IS" BASIS, 14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15See the License for the specific language governing permissions and 16limitations under the License. 17*/ 18 19package azuredd 20 21import ( 22 "os" 23 "testing" 24 25 "github.com/stretchr/testify/assert" 26 27 "k8s.io/api/core/v1" 28 utiltesting "k8s.io/client-go/util/testing" 29 "k8s.io/kubernetes/pkg/volume" 30 volumetest "k8s.io/kubernetes/pkg/volume/testing" 31) 32 33func TestCanSupport(t *testing.T) { 34 tmpDir, err := utiltesting.MkTmpdir("azure_dd") 35 if err != nil { 36 t.Fatalf("can't make a temp dir: %v", err) 37 } 38 defer os.RemoveAll(tmpDir) 39 plugMgr := volume.VolumePluginMgr{} 40 plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeKubeletVolumeHost(t, tmpDir, nil, nil)) 41 42 plug, err := plugMgr.FindPluginByName(azureDataDiskPluginName) 43 if err != nil { 44 t.Fatal("Can't find the plugin by name") 45 } 46 if plug.GetPluginName() != azureDataDiskPluginName { 47 t.Errorf("Wrong name: %s", plug.GetPluginName()) 48 } 49 if !plug.CanSupport(&volume.Spec{Volume: &v1.Volume{VolumeSource: v1.VolumeSource{AzureDisk: &v1.AzureDiskVolumeSource{}}}}) { 50 t.Errorf("Expected true") 51 } 52 53 if !plug.CanSupport(&volume.Spec{PersistentVolume: &v1.PersistentVolume{Spec: v1.PersistentVolumeSpec{PersistentVolumeSource: v1.PersistentVolumeSource{AzureDisk: &v1.AzureDiskVolumeSource{}}}}}) { 54 t.Errorf("Expected true") 55 } 56} 57 58// fakeAzureProvider type was removed because all functions were not used 59// Testing mounting will require path calculation which depends on the cloud provider, which is faked in the above test. 60 61func TestGetMaxDataDiskCount(t *testing.T) { 62 tests := []struct { 63 instanceType string 64 expectResult int64 65 }{ 66 { 67 instanceType: "standard_d2_v2", 68 expectResult: 8, 69 }, 70 { 71 instanceType: "Standard_DS14_V2", 72 expectResult: 64, 73 }, 74 { 75 instanceType: "NOT_EXISTING", 76 expectResult: defaultAzureVolumeLimit, 77 }, 78 { 79 instanceType: "", 80 expectResult: defaultAzureVolumeLimit, 81 }, 82 } 83 84 for _, test := range tests { 85 result := getMaxDataDiskCount(test.instanceType) 86 assert.Equal(t, test.expectResult, result) 87 } 88} 89 90func TestUnsupportedVolumeHost(t *testing.T) { 91 tmpDir, err := utiltesting.MkTmpdir("azure_dd") 92 if err != nil { 93 t.Fatalf("can't make a temp dir: %v", err) 94 } 95 defer os.RemoveAll(tmpDir) 96 plugMgr := volume.VolumePluginMgr{} 97 plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeKubeletVolumeHost(t, tmpDir, nil, nil)) 98 99 plug, err := plugMgr.FindPluginByName(azureDataDiskPluginName) 100 if err != nil { 101 t.Fatal("Can't find the plugin by name") 102 } 103 104 _, err = plug.ConstructVolumeSpec("", "") 105 if err == nil { 106 t.Errorf("Expected failure constructing volume spec with unsupported VolumeHost") 107 } 108} 109