...

Source file src/go.einride.tech/aip/resourceid/usersettable_test.go

Documentation: go.einride.tech/aip/resourceid

     1  package resourceid
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gotest.tools/v3/assert"
     7  )
     8  
     9  func TestValidateUserSettable(t *testing.T) {
    10  	t.Parallel()
    11  	for _, tt := range []struct {
    12  		id            string
    13  		errorContains string
    14  	}{
    15  		{id: "abcd"},
    16  		{id: "abcd-efgh-1234"},
    17  		{id: "abc", errorContains: "must be between 4 and 63 characters"},
    18  		{id: "-abc", errorContains: "must begin with a letter"},
    19  		{id: "abc-", errorContains: "must end with a letter or number"},
    20  		{id: "123-abc", errorContains: "must begin with a letter"},
    21  		{id: "daf1cb3e-f33b-43f1-81cc-e65fda51efa5", errorContains: "must not be a valid UUIDv4"},
    22  		{id: "abcd/efgh", errorContains: "must only contain lowercase, numbers and hyphens"},
    23  	} {
    24  		tt := tt
    25  		t.Run(tt.id, func(t *testing.T) {
    26  			t.Parallel()
    27  			err := ValidateUserSettable(tt.id)
    28  			if tt.errorContains != "" {
    29  				assert.ErrorContains(t, err, tt.errorContains)
    30  			} else {
    31  				assert.NilError(t, err)
    32  			}
    33  		})
    34  	}
    35  }
    36  

View as plain text