github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/validation/uuid_test.go (about)

     1  package validation
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestValidationIsUUID(t *testing.T) {
     8  	cases := map[string]struct {
     9  		Value interface{}
    10  		Error bool
    11  	}{
    12  		"NotString": {
    13  			Value: 7,
    14  			Error: true,
    15  		},
    16  		"Empty": {
    17  			Value: "",
    18  			Error: true,
    19  		},
    20  		"InvalidUuid": {
    21  			Value: "00000000-0000-123-0000-000000000000",
    22  			Error: true,
    23  		},
    24  		"ValidUuidWithOutDashs": {
    25  			Value: "12345678123412341234123456789012",
    26  			Error: true,
    27  		},
    28  		"ValidUuid": {
    29  			Value: "00000000-0000-0000-0000-000000000000",
    30  			Error: false,
    31  		},
    32  	}
    33  
    34  	for tn, tc := range cases {
    35  		t.Run(tn, func(t *testing.T) {
    36  			_, errors := IsUUID(tc.Value, tn)
    37  
    38  			if len(errors) > 0 && !tc.Error {
    39  				t.Errorf("IsUUID(%s) produced an unexpected error", tc.Value)
    40  			} else if len(errors) == 0 && tc.Error {
    41  				t.Errorf("IsUUID(%s) did not error", tc.Value)
    42  			}
    43  		})
    44  	}
    45  }