Skip to content

Commit

Permalink
Add validation test for disk encryption set name
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang authored and tombuildsstuff committed Jan 9, 2020
1 parent 420ac7a commit 3f2b59c
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions azurerm/internal/services/compute/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,81 @@ func TestParseVirtualMachineScaleSetID(t *testing.T) {
}
}
}

func TestValidateDiskEncryptionSetName(t *testing.T) {
testData := []struct {
input string
expected bool
}{
{
// empty
input: "",
expected: false,
},
{
//basic example
input: "hello",
expected: true,
},
{
// can't start with an underscore
input: "_hello",
expected: false,
},
{
// can't start with dot
input: ".hello",
expected: false,
},
{
// dot in middle
input: "hello.world",
expected: true,
},
{
// hyphen in middle
input: "hello-world",
expected: true,
},
{
// can't end with hyphen
input: "helloworld-",
expected: false,
},
{
// can't contain an exclamation mark
input: "hello!",
expected: false,
},
{
// can't end with dot
input: "hello.",
expected: false,
},
{
// underscore at end
input: "helloworld_",
expected: true,
},
{
// 80 characters
input: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
expected: true,
},
{
// 81 characters
input: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdef",
expected: false,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q...", v.input)

_, errors := validateDiskEncryptionSetName(v.input, "name")
actual := len(errors) == 0
if v.expected != actual {
t.Fatalf("Expected %t but got %t", v.expected, actual)
}
}
}

0 comments on commit 3f2b59c

Please sign in to comment.