-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 #1795 from fabotronix/master
Fix: Corrected regexp for eventhub name
- Loading branch information
Showing
2 changed files
with
72 additions
and
7 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,65 @@ | ||
package azure | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestValidateEventHubName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
valid bool | ||
}{ | ||
{ | ||
name: "Valid short name", | ||
input: "abc", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid short name", | ||
input: "a", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid name with dot", | ||
input: "a.b", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Just a digit", | ||
input: "1", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Invalid long name", | ||
input: strings.Repeat("a", 51), | ||
valid: false, | ||
}, | ||
{ | ||
name: "Invalid short name", | ||
input: ".", | ||
valid: false, | ||
}, | ||
{ | ||
name: "Invalid name with period at end", | ||
input: "a.", | ||
valid: false, | ||
}, | ||
{ | ||
name: "empty name", | ||
input: "", | ||
valid: false, | ||
}, | ||
} | ||
var validationFunction = ValidateEventHubName() | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
_, err := validationFunction(tt.input, "") | ||
valid := err == nil | ||
if valid != tt.valid { | ||
t.Errorf("Expected valid status %t but got %t for input %s", tt.valid, valid, tt.input) | ||
} | ||
}) | ||
} | ||
} |