github.com/kubernetes-incubator/kube-aws@v0.16.4/cfnresource/naming_test.go (about) 1 package cfnresource 2 3 import "testing" 4 5 func TestValidateRoleNameLength(t *testing.T) { 6 t.Run("WhenMax", func(t *testing.T) { 7 if e := ValidateUnstableRoleNameLength("my-firstcluster", "prodWorkerks", "prod-workers", "us-east-1", false); e != nil { 8 t.Errorf("expected validation to succeed but failed: %v", e) 9 } 10 }) 11 t.Run("WhenTooLong", func(t *testing.T) { 12 if e := ValidateUnstableRoleNameLength("my-secondcluster", "prodWorkerks", "prod-workers", "us-east-1", false); e == nil { 13 t.Error("expected validation to fail but succeeded") 14 } 15 }) 16 } 17 18 func TestValidateManagedRoleNameLength(t *testing.T) { 19 t.Run("WhenMax", func(t *testing.T) { 20 if e := ValidateStableRoleNameLength("prod", "workers", "ap-southeast-1", false); e != nil { 21 t.Errorf("expected validation to succeed but failed: %v", e) 22 } 23 }) 24 t.Run("WhenTooLong", func(t *testing.T) { 25 if e := ValidateStableRoleNameLength("prod", "workers-role-with-very-very-very-very-very-long-name", "ap-southeast-1", false); e == nil { 26 t.Error("expected validation to fail but succeeded") 27 } 28 }) 29 } 30 31 func TestValidateManagedRoleStrictNameLength(t *testing.T) { 32 t.Run("WhenMax", func(t *testing.T) { 33 if e := ValidateStableRoleNameLength("prod", "workers-role-with-very-very-very-very-very-long-name", "ap-southeast-1", true); e != nil { 34 t.Errorf("expected validation to succeed but failed: %v", e) 35 } 36 }) 37 t.Run("WhenTooLong", func(t *testing.T) { 38 if e := ValidateStableRoleNameLength("prod", "workers-role-with-very-very-very-very-very-long-name-very-very-very-very-very-long-name", "ap-southeast-1", true); e == nil { 39 t.Error("expected validation to fail but succeeded") 40 } 41 }) 42 }