github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cmd/create/create_cluster_gke_test.go (about) 1 // +build unit 2 3 package create 4 5 import ( 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func Test_validateClusterName(t *testing.T) { 12 var bigLongName = string("this-name-is-too-long-by-one") 13 var capitalName = string("NameWithCapitalLetters") 14 var gibberishName = string("l337n@me") 15 var goodName = string("good-name-for-cluster") 16 t.Parallel() 17 tests := []struct { 18 name string 19 clusterName string 20 want bool 21 }{ 22 // Negative tests for bad names. Should return false. 23 {"Fails when too long", bigLongName, false}, 24 {"Fails with capital letters", capitalName, false}, 25 {"Fails with gibberish name", gibberishName, false}, 26 // Positive tests with good names. Should return true. 27 {"Passes with good name", goodName, true}, 28 } 29 for _, tt := range tests { 30 t.Run(tt.name, func(t *testing.T) { 31 err := validateClusterName(tt.clusterName) 32 nameIsValid := false 33 if err == nil { 34 nameIsValid = true 35 } 36 assert.Equal(t, nameIsValid, tt.want) 37 }) 38 } 39 } 40 41 func TestAddLabel(t *testing.T) { 42 label := AddLabel("", "created-by", "test.user") 43 assert.Equal(t, "created-by=test-user", label, "Label formed incorrectly") 44 }