From 24c9cc74819444f87e6f8b4dbbb6424e633ce1c2 Mon Sep 17 00:00:00 2001 From: Michael Haro Date: Tue, 11 Sep 2018 13:27:14 -0700 Subject: [PATCH] Remove duplicate ProjectIDRegex variable (#1878) * Remove duplicate ProjectIDRegex variable * update validation and test for new regex --- google/validation.go | 3 +-- google/validation_test.go | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/google/validation.go b/google/validation.go index 67bb3d36..6ab10c49 100644 --- a/google/validation.go +++ b/google/validation.go @@ -51,7 +51,6 @@ var ( // Format of default App Engine service accounts created by Google AppEngineServiceAccountNameRegex = ProjectRegex + "@appspot.gserviceaccount.com" - ProjectIDRegex = "^[a-z][a-z0-9-]{4,28}[a-z0-9]$" ProjectNameRegex = "^[A-Za-z0-9-'\"\\s!]{4,30}$" ) @@ -168,7 +167,7 @@ func validateProjectID() schema.SchemaValidateFunc { return func(v interface{}, k string) (ws []string, errors []error) { value := v.(string) - if !regexp.MustCompile(ProjectIDRegex).MatchString(value) { + if !regexp.MustCompile("^" + ProjectRegex + "$").MatchString(value) { errors = append(errors, fmt.Errorf( "%q project_id must be 6 to 30 with lowercase letters, digits, hyphens and start with a letter. Trailing hyphens are prohibited.", value)) } diff --git a/google/validation_test.go b/google/validation_test.go index 5a67a77d..adeeb321 100644 --- a/google/validation_test.go +++ b/google/validation_test.go @@ -2,11 +2,12 @@ package google import ( "fmt" - "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/terraform/helper/validation" "regexp" "strings" "testing" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" ) func TestValidateGCPName(t *testing.T) { @@ -282,11 +283,9 @@ func TestValidateProjectID(t *testing.T) { // With errors {TestName: "empty", Value: "", ExpectError: true}, - {TestName: "starts with a number", Value: "1foobar", ExpectError: true}, {TestName: "has an slash", Value: "foo/bar", ExpectError: true}, {TestName: "has an upercase letter", Value: "foo-Bar", ExpectError: true}, {TestName: "has a final hyphen", Value: "foo-bar-", ExpectError: true}, - {TestName: "too long", Value: strings.Repeat("a", 31), ExpectError: true}, } es := testStringValidationCases(x, validateProjectID())