-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
219 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azure | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestIsAvailabilityZone(t *testing.T) { | ||
location := "eastus" | ||
az := &Cloud{ | ||
Config: Config{ | ||
Location: location, | ||
}, | ||
} | ||
tests := []struct { | ||
desc string | ||
zone string | ||
expected bool | ||
}{ | ||
{"empty string should return false", "", false}, | ||
{"wrong farmat should return false", "123", false}, | ||
{"wrong location should return false", "chinanorth-1", false}, | ||
{"correct zone should return true", "eastus-1", true}, | ||
} | ||
|
||
for _, test := range tests { | ||
actual := az.isAvailabilityZone(test.zone) | ||
if actual != test.expected { | ||
t.Errorf("test [%q] get unexpected result: %v != %v", test.desc, actual, test.expected) | ||
} | ||
} | ||
} | ||
|
||
func TestGetZoneID(t *testing.T) { | ||
location := "eastus" | ||
az := &Cloud{ | ||
Config: Config{ | ||
Location: location, | ||
}, | ||
} | ||
tests := []struct { | ||
desc string | ||
zone string | ||
expected string | ||
}{ | ||
{"empty string should return empty string", "", ""}, | ||
{"wrong farmat should return empty string", "123", ""}, | ||
{"wrong location should return empty string", "chinanorth-1", ""}, | ||
{"correct zone should return zone ID", "eastus-1", "1"}, | ||
} | ||
|
||
for _, test := range tests { | ||
actual := az.GetZoneID(test.zone) | ||
if actual != test.expected { | ||
t.Errorf("test [%q] get unexpected result: %q != %q", test.desc, actual, test.expected) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azure_dd | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/api/core/v1" | ||
) | ||
|
||
func TestParseZoned(t *testing.T) { | ||
tests := []struct { | ||
msg string | ||
zoneString string | ||
diskKind v1.AzureDataDiskKind | ||
expected bool | ||
expectError bool | ||
}{ | ||
{ | ||
msg: "managed disk should default to zoned", | ||
diskKind: v1.AzureManagedDisk, | ||
expected: true, | ||
}, | ||
{ | ||
msg: "shared blob disk should default to un-zoned", | ||
diskKind: v1.AzureSharedBlobDisk, | ||
expected: false, | ||
}, | ||
{ | ||
msg: "shared dedicated disk should default to un-zoned", | ||
diskKind: v1.AzureDedicatedBlobDisk, | ||
expected: false, | ||
}, | ||
{ | ||
msg: "managed disk should support zoned=true", | ||
diskKind: v1.AzureManagedDisk, | ||
zoneString: "true", | ||
expected: true, | ||
}, | ||
{ | ||
msg: "managed disk should support zoned=false", | ||
diskKind: v1.AzureManagedDisk, | ||
zoneString: "false", | ||
expected: false, | ||
}, | ||
{ | ||
msg: "shared blob disk should support zoned=false", | ||
diskKind: v1.AzureSharedBlobDisk, | ||
zoneString: "false", | ||
expected: false, | ||
}, | ||
{ | ||
msg: "shared blob disk shouldn't support zoned=true", | ||
diskKind: v1.AzureSharedBlobDisk, | ||
zoneString: "true", | ||
expectError: true, | ||
}, | ||
{ | ||
msg: "shared dedicated disk should support zoned=false", | ||
diskKind: v1.AzureDedicatedBlobDisk, | ||
zoneString: "false", | ||
expected: false, | ||
}, | ||
{ | ||
msg: "dedicated blob disk shouldn't support zoned=true", | ||
diskKind: v1.AzureDedicatedBlobDisk, | ||
zoneString: "true", | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for i, test := range tests { | ||
real, err := parseZoned(test.zoneString, test.diskKind) | ||
if test.expectError { | ||
assert.Error(t, err, fmt.Sprintf("TestCase[%d]: %s", i, test.msg)) | ||
} else { | ||
assert.Equal(t, test.expected, real, fmt.Sprintf("TestCase[%d]: %s", i, test.msg)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters