Skip to content

Commit

Permalink
helper/validation: UUID -> IsUUID (#297)
Browse files Browse the repository at this point in the history
rename: UUID -> IsValidUUID

Co-authored-by: appilon <apilon@hashicorp.com>
  • Loading branch information
radeksimko and appilon committed Jan 15, 2020
1 parent 837c1a1 commit 7b90253
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 2 additions & 6 deletions helper/validation/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}$")

// UUID is a ValidateFunc that ensures a string can be parsed as UUID
func UUID(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))
Expand Down
8 changes: 4 additions & 4 deletions helper/validation/uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
)

func TestValidationUUID(t *testing.T) {
func TestValidationIsUUID(t *testing.T) {
cases := map[string]struct {
Value interface{}
Error bool
Expand Down Expand Up @@ -33,12 +33,12 @@ func TestValidationUUID(t *testing.T) {

for tn, tc := range cases {
t.Run(tn, func(t *testing.T) {
_, errors := UUID(tc.Value, tn)
_, 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)
}
})
}
Expand Down

0 comments on commit 7b90253

Please sign in to comment.