azure_dd_test.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Copyright 2015 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 azure_dd
  14. import (
  15. "os"
  16. "testing"
  17. "github.com/stretchr/testify/assert"
  18. "k8s.io/api/core/v1"
  19. utiltesting "k8s.io/client-go/util/testing"
  20. "k8s.io/kubernetes/pkg/volume"
  21. volumetest "k8s.io/kubernetes/pkg/volume/testing"
  22. )
  23. func TestCanSupport(t *testing.T) {
  24. tmpDir, err := utiltesting.MkTmpdir("azure_dd")
  25. if err != nil {
  26. t.Fatalf("can't make a temp dir: %v", err)
  27. }
  28. defer os.RemoveAll(tmpDir)
  29. plugMgr := volume.VolumePluginMgr{}
  30. plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeVolumeHost(tmpDir, nil, nil))
  31. plug, err := plugMgr.FindPluginByName(azureDataDiskPluginName)
  32. if err != nil {
  33. t.Errorf("Can't find the plugin by name")
  34. }
  35. if plug.GetPluginName() != azureDataDiskPluginName {
  36. t.Errorf("Wrong name: %s", plug.GetPluginName())
  37. }
  38. if !plug.CanSupport(&volume.Spec{Volume: &v1.Volume{VolumeSource: v1.VolumeSource{AzureDisk: &v1.AzureDiskVolumeSource{}}}}) {
  39. t.Errorf("Expected true")
  40. }
  41. if !plug.CanSupport(&volume.Spec{PersistentVolume: &v1.PersistentVolume{Spec: v1.PersistentVolumeSpec{PersistentVolumeSource: v1.PersistentVolumeSource{AzureDisk: &v1.AzureDiskVolumeSource{}}}}}) {
  42. t.Errorf("Expected true")
  43. }
  44. }
  45. // fakeAzureProvider type was removed because all functions were not used
  46. // Testing mounting will require path calculation which depends on the cloud provider, which is faked in the above test.
  47. func TestGetMaxDataDiskCount(t *testing.T) {
  48. tests := []struct {
  49. instanceType string
  50. expectResult int64
  51. }{
  52. {
  53. instanceType: "standard_d2_v2",
  54. expectResult: 8,
  55. },
  56. {
  57. instanceType: "NOT_EXISTING",
  58. expectResult: defaultAzureVolumeLimit,
  59. },
  60. {
  61. instanceType: "",
  62. expectResult: defaultAzureVolumeLimit,
  63. },
  64. }
  65. for _, test := range tests {
  66. result := getMaxDataDiskCount(test.instanceType)
  67. assert.Equal(t, test.expectResult, result)
  68. }
  69. }