azure_provision_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // +build !providerless
  2. /*
  3. Copyright 2018 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package azure_dd
  15. import (
  16. "fmt"
  17. "testing"
  18. "github.com/stretchr/testify/assert"
  19. "k8s.io/api/core/v1"
  20. )
  21. func TestParseZoned(t *testing.T) {
  22. tests := []struct {
  23. msg string
  24. zoneString string
  25. diskKind v1.AzureDataDiskKind
  26. expected bool
  27. expectError bool
  28. }{
  29. {
  30. msg: "managed disk should default to zoned",
  31. diskKind: v1.AzureManagedDisk,
  32. expected: true,
  33. },
  34. {
  35. msg: "shared blob disk should default to un-zoned",
  36. diskKind: v1.AzureSharedBlobDisk,
  37. expected: false,
  38. },
  39. {
  40. msg: "shared dedicated disk should default to un-zoned",
  41. diskKind: v1.AzureDedicatedBlobDisk,
  42. expected: false,
  43. },
  44. {
  45. msg: "managed disk should support zoned=true",
  46. diskKind: v1.AzureManagedDisk,
  47. zoneString: "true",
  48. expected: true,
  49. },
  50. {
  51. msg: "managed disk should support zoned=false",
  52. diskKind: v1.AzureManagedDisk,
  53. zoneString: "false",
  54. expected: false,
  55. },
  56. {
  57. msg: "shared blob disk should support zoned=false",
  58. diskKind: v1.AzureSharedBlobDisk,
  59. zoneString: "false",
  60. expected: false,
  61. },
  62. {
  63. msg: "shared blob disk shouldn't support zoned=true",
  64. diskKind: v1.AzureSharedBlobDisk,
  65. zoneString: "true",
  66. expectError: true,
  67. },
  68. {
  69. msg: "shared dedicated disk should support zoned=false",
  70. diskKind: v1.AzureDedicatedBlobDisk,
  71. zoneString: "false",
  72. expected: false,
  73. },
  74. {
  75. msg: "dedicated blob disk shouldn't support zoned=true",
  76. diskKind: v1.AzureDedicatedBlobDisk,
  77. zoneString: "true",
  78. expectError: true,
  79. },
  80. }
  81. for i, test := range tests {
  82. real, err := parseZoned(test.zoneString, test.diskKind)
  83. if test.expectError {
  84. assert.Error(t, err, fmt.Sprintf("TestCase[%d]: %s", i, test.msg))
  85. } else {
  86. assert.Equal(t, test.expected, real, fmt.Sprintf("TestCase[%d]: %s", i, test.msg))
  87. }
  88. }
  89. }