Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7083 from neil-yechenwei/sbnamevalidate
Fix validation for serivce bus topic name
- Loading branch information
Showing
2 changed files
with
78 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package azure | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestValidateServiceBusTopicName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
valid bool | ||
}{ | ||
{ | ||
name: "Empty value", | ||
input: "", | ||
valid: false, | ||
}, | ||
{ | ||
name: "Invalid name with only 1 letter", | ||
input: "a", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Invalid name starts with underscore", | ||
input: "_a", | ||
valid: false, | ||
}, | ||
{ | ||
name: "Invalid name ends with period", | ||
input: "a.", | ||
valid: false, | ||
}, | ||
{ | ||
name: "Valid name with numbers", | ||
input: "12345", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid name with only 1 number", | ||
input: "1", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid name with hyphens", | ||
input: "malcolm-in-the-middle", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid name with 259 characters", | ||
input: strings.Repeat("w", 259), | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid name with 260 characters", | ||
input: strings.Repeat("w", 260), | ||
valid: true, | ||
}, | ||
{ | ||
name: "Invalid name with 261 characters", | ||
input: strings.Repeat("w", 261), | ||
valid: false, | ||
}, | ||
} | ||
|
||
var validationFunction = ValidateServiceBusTopicName() | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
_, err := validationFunction(tt.input, "name") | ||
valid := err == nil | ||
if valid != tt.valid { | ||
t.Errorf("Expected valid status %t but got %t for input %s", tt.valid, valid, tt.input) | ||
} | ||
}) | ||
} | ||
} |