-
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.
New Resource:
azurerm_cognitive_account
(#962)
* New Resource: `azurerm_cognitive_account` * Updating to v21.1.0 of the Azure SDK
- Loading branch information
1 parent
ae174ca
commit f7d0257
Showing
16 changed files
with
2,892 additions
and
0 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,15 @@ | ||
package validate | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
) | ||
|
||
func CognitiveServicesAccountName() schema.SchemaValidateFunc { | ||
return validation.StringMatch( | ||
regexp.MustCompile("^([a-zA-Z0-9]{1}[a-zA-Z0-9_.-]{1,})$"), | ||
"The Cognitive Services Account Name can only start with an alphanumeric character, and must only contain alphanumeric characters, periods, dashes or underscores.", | ||
) | ||
} |
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,78 @@ | ||
package validate | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestValidateCognitiveServicesAccountName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
valid bool | ||
}{ | ||
{ | ||
name: "empty name", | ||
input: "", | ||
valid: false, | ||
}, | ||
{ | ||
name: "Valid short name", | ||
input: "abc", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Invalid short name", | ||
input: "a", | ||
valid: false, | ||
}, | ||
{ | ||
name: "Valid short name", | ||
input: "ab", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid long name", | ||
input: "abc_-.123", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid with a digit at the end", | ||
input: "hello1", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid with a digit in the middle", | ||
input: "hello1", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Invalid with a digit at the start", | ||
input: "1hello", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Invalid with a period at the start", | ||
input: ".heyo", | ||
valid: false, | ||
}, | ||
{ | ||
name: "Valid name with period in the middle", | ||
input: "a.bc", | ||
valid: true, | ||
}, | ||
{ | ||
name: "Valid name with period at end", | ||
input: "a.", | ||
valid: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
_, err := CognitiveServicesAccountName()(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) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.