azure_provision_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Copyright 2018 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. "fmt"
  16. "testing"
  17. "github.com/stretchr/testify/assert"
  18. "k8s.io/api/core/v1"
  19. )
  20. func TestParseZoned(t *testing.T) {
  21. tests := []struct {
  22. msg string
  23. zoneString string
  24. diskKind v1.AzureDataDiskKind
  25. expected bool
  26. expectError bool
  27. }{
  28. {
  29. msg: "managed disk should default to zoned",
  30. diskKind: v1.AzureManagedDisk,
  31. expected: true,
  32. },
  33. {
  34. msg: "shared blob disk should default to un-zoned",
  35. diskKind: v1.AzureSharedBlobDisk,
  36. expected: false,
  37. },
  38. {
  39. msg: "shared dedicated disk should default to un-zoned",
  40. diskKind: v1.AzureDedicatedBlobDisk,
  41. expected: false,
  42. },
  43. {
  44. msg: "managed disk should support zoned=true",
  45. diskKind: v1.AzureManagedDisk,
  46. zoneString: "true",
  47. expected: true,
  48. },
  49. {
  50. msg: "managed disk should support zoned=false",
  51. diskKind: v1.AzureManagedDisk,
  52. zoneString: "false",
  53. expected: false,
  54. },
  55. {
  56. msg: "shared blob disk should support zoned=false",
  57. diskKind: v1.AzureSharedBlobDisk,
  58. zoneString: "false",
  59. expected: false,
  60. },
  61. {
  62. msg: "shared blob disk shouldn't support zoned=true",
  63. diskKind: v1.AzureSharedBlobDisk,
  64. zoneString: "true",
  65. expectError: true,
  66. },
  67. {
  68. msg: "shared dedicated disk should support zoned=false",
  69. diskKind: v1.AzureDedicatedBlobDisk,
  70. zoneString: "false",
  71. expected: false,
  72. },
  73. {
  74. msg: "dedicated blob disk shouldn't support zoned=true",
  75. diskKind: v1.AzureDedicatedBlobDisk,
  76. zoneString: "true",
  77. expectError: true,
  78. },
  79. }
  80. for i, test := range tests {
  81. real, err := parseZoned(test.zoneString, test.diskKind)
  82. if test.expectError {
  83. assert.Error(t, err, fmt.Sprintf("TestCase[%d]: %s", i, test.msg))
  84. } else {
  85. assert.Equal(t, test.expected, real, fmt.Sprintf("TestCase[%d]: %s", i, test.msg))
  86. }
  87. }
  88. }