-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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 #6064 from njuCZ/issue_6062
`azurerm_postgresql_server` - align server name validation rule with the portal
- Loading branch information
Showing
2 changed files
with
70 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,68 @@ | ||
package postgres | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestValidatePSQLServerName(t *testing.T) { | ||
testData := []struct { | ||
input string | ||
expected bool | ||
}{ | ||
{ | ||
// empty | ||
input: "", | ||
expected: false, | ||
}, | ||
{ | ||
// basic example | ||
input: "ab-c", | ||
expected: true, | ||
}, | ||
{ | ||
// can't contain upper case letter | ||
input: "AbcD", | ||
expected: false, | ||
}, | ||
{ | ||
// can't start with a hyphen | ||
input: "-abc", | ||
expected: false, | ||
}, | ||
{ | ||
// can't contain underscore | ||
input: "ab_c", | ||
expected: false, | ||
}, | ||
{ | ||
// can't end with hyphen | ||
input: "abc-", | ||
expected: false, | ||
}, | ||
{ | ||
// can not short than 3 characters | ||
input: "ab", | ||
expected: false, | ||
}, | ||
{ | ||
// 63 chars | ||
input: "abcdefghijklmnopqrstuvwxyzabcdefabcdefghijklmnopqrstuvwxyzabcde", | ||
expected: true, | ||
}, | ||
{ | ||
// 64 chars | ||
input: "abcdefghijklmnopqrstuvwxyzabcdefabcdefghijklmnopqrstuvwxyzabcdef", | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q..", v.input) | ||
|
||
_, errors := ValidatePSQLServerName(v.input, "name") | ||
actual := len(errors) == 0 | ||
if v.expected != actual { | ||
t.Fatalf("Expected %t but got %t", v.expected, actual) | ||
} | ||
} | ||
} |