From 1bd87eb21ba52f72ffd6639ac356dd659c41afd0 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 15 Jan 2020 08:44:29 +0000 Subject: [PATCH 1/3] helper/validation: UUID -> IsValidUUID --- helper/validation/uuid.go | 8 ++++---- helper/validation/uuid_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/helper/validation/uuid.go b/helper/validation/uuid.go index 1e4939b98e..c1c81cb5fc 100644 --- a/helper/validation/uuid.go +++ b/helper/validation/uuid.go @@ -7,11 +7,11 @@ import ( "github.com/hashicorp/go-uuid" ) -// UUIDRegExp is a Regular Expression that can be used to validate UUIDs -var UUIDRegExp = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$") +// uuidRegExp is a Regular Expression that can be used to validate UUIDs +var uuidRegExp = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$") -// UUID is a ValidateFunc that ensures a string can be parsed as UUID -func UUID(i interface{}, k string) (warnings []string, errors []error) { +// IsValidUUID is a ValidateFunc that ensures a string can be parsed as UUID +func IsValidUUID(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) diff --git a/helper/validation/uuid_test.go b/helper/validation/uuid_test.go index b3960779fc..2f48e0da77 100644 --- a/helper/validation/uuid_test.go +++ b/helper/validation/uuid_test.go @@ -33,7 +33,7 @@ func TestValidationUUID(t *testing.T) { for tn, tc := range cases { t.Run(tn, func(t *testing.T) { - _, errors := UUID(tc.Value, tn) + _, errors := IsValidUUID(tc.Value, tn) if len(errors) > 0 && !tc.Error { t.Errorf("UUID(%s) produced an unexpected error", tc.Value) From e8cf1f6da3fe89f57b5ca78e55c87722f8495516 Mon Sep 17 00:00:00 2001 From: Alex Pilon Date: Wed, 15 Jan 2020 17:01:51 -0500 Subject: [PATCH 2/3] remove uuid regex rename IsValidUUID to IsUUID --- helper/validation/uuid.go | 8 ++------ helper/validation/uuid_test.go | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/helper/validation/uuid.go b/helper/validation/uuid.go index c1c81cb5fc..00783fafce 100644 --- a/helper/validation/uuid.go +++ b/helper/validation/uuid.go @@ -2,16 +2,12 @@ package validation import ( "fmt" - "regexp" "github.com/hashicorp/go-uuid" ) -// uuidRegExp is a Regular Expression that can be used to validate UUIDs -var uuidRegExp = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$") - -// IsValidUUID is a ValidateFunc that ensures a string can be parsed as UUID -func IsValidUUID(i interface{}, k string) (warnings []string, errors []error) { +// IsUUID is a ValidateFunc that ensures a string can be parsed as UUID +func IsUUID(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) diff --git a/helper/validation/uuid_test.go b/helper/validation/uuid_test.go index 2f48e0da77..3f0a2b4aa4 100644 --- a/helper/validation/uuid_test.go +++ b/helper/validation/uuid_test.go @@ -33,7 +33,7 @@ func TestValidationUUID(t *testing.T) { for tn, tc := range cases { t.Run(tn, func(t *testing.T) { - _, errors := IsValidUUID(tc.Value, tn) + _, errors := IsUUID(tc.Value, tn) if len(errors) > 0 && !tc.Error { t.Errorf("UUID(%s) produced an unexpected error", tc.Value) From 7e6df31ad518bc981be912b733aaddb8d51579de Mon Sep 17 00:00:00 2001 From: Alex Pilon Date: Wed, 15 Jan 2020 17:17:29 -0500 Subject: [PATCH 3/3] update func name reference --- helper/validation/uuid_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helper/validation/uuid_test.go b/helper/validation/uuid_test.go index 3f0a2b4aa4..b8bb1505b9 100644 --- a/helper/validation/uuid_test.go +++ b/helper/validation/uuid_test.go @@ -4,7 +4,7 @@ import ( "testing" ) -func TestValidationUUID(t *testing.T) { +func TestValidationIsUUID(t *testing.T) { cases := map[string]struct { Value interface{} Error bool @@ -36,9 +36,9 @@ func TestValidationUUID(t *testing.T) { _, errors := IsUUID(tc.Value, tn) if len(errors) > 0 && !tc.Error { - t.Errorf("UUID(%s) produced an unexpected error", tc.Value) + t.Errorf("IsUUID(%s) produced an unexpected error", tc.Value) } else if len(errors) == 0 && tc.Error { - t.Errorf("UUID(%s) did not error", tc.Value) + t.Errorf("IsUUID(%s) did not error", tc.Value) } }) }