-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r/maps_account: changes from code review
- Loading branch information
1 parent
b7746b7
commit c46fc43
Showing
10 changed files
with
154 additions
and
106 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
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,14 @@ | ||
package maps | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
) | ||
|
||
func ValidateName() schema.SchemaValidateFunc { | ||
return validation.StringMatch( | ||
regexp.MustCompile(`^[A-Za-z0-9]{1}[A-Za-z0-9\._-]{1,}$`), | ||
"First character must be alphanumeric. Subsequent character(s) must be any combination of alphanumeric, underscore (_), period (.), or hyphen (-).") | ||
} |
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,69 @@ | ||
package maps | ||
|
||
import "testing" | ||
|
||
func TestValidateName(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Expected bool | ||
}{ | ||
{ | ||
Name: "", | ||
Expected: false, | ||
}, | ||
{ | ||
Name: "hello", | ||
Expected: true, | ||
}, | ||
{ | ||
Name: "Hello", | ||
Expected: true, | ||
}, | ||
{ | ||
Name: "1hello", | ||
Expected: true, | ||
}, | ||
{ | ||
Name: "1he-llo", | ||
Expected: true, | ||
}, | ||
{ | ||
Name: "he-llo1", | ||
Expected: true, | ||
}, | ||
{ | ||
Name: "he_llo1", | ||
Expected: true, | ||
}, | ||
{ | ||
Name: ".hello1", | ||
Expected: false, | ||
}, | ||
{ | ||
Name: "_hello1", | ||
Expected: false, | ||
}, | ||
{ | ||
Name: "he.llo1", | ||
Expected: true, | ||
}, | ||
{ | ||
Name: "he-llo!", | ||
Expected: false, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
warnings, errors := ValidateName()(v.Name, "name") | ||
if len(warnings) != 0 { | ||
t.Fatalf("Expected no warnings but got %d", len(warnings)) | ||
} | ||
|
||
actual := len(errors) == 0 | ||
if v.Expected != actual { | ||
t.Fatalf("Expected %t but got %t for %q: %s", v.Expected, actual, v.Name, errors) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.