diff --git a/pkg/data/cloud/platform.go b/pkg/data/cloud/platform.go index 80aedcb4..3433460a 100644 --- a/pkg/data/cloud/platform.go +++ b/pkg/data/cloud/platform.go @@ -8,25 +8,25 @@ import ( // Platform type represents specific Platform types and how they map to their respective platforms. type Platform struct { - // names holds 2 unique lowercase names of the Platform (e.g., "aws"). We use a fixed- - // size array so that this struct remains comparable. Any of the 2 values can be used to refer + // names holds 3 unique lowercase names of the Platform (e.g., "aws"). We use a fixed- + // size array so that this struct remains comparable. Any of the 3 values can be used to refer // to this specific Platform via Platform.ByName(), but only the first (element // 0) element will be the "preferred name" returned by Platform.String() - names [2]string + names [3]string } var ( AWSClassic = Platform{ - names: [2]string{"aws-classic", "aws"}, + names: [3]string{"aws-classic", "aws"}, } AWSHCP = Platform{ - names: [2]string{"aws-hcp", "hostedcluster"}, + names: [3]string{"aws-hcp", "aws-hosted-cp", "hostedcluster"}, } AWSHCPZeroEgress = Platform{ - names: [2]string{"aws-hcp-zeroegress"}, + names: [3]string{"aws-hcp-zeroegress"}, } GCPClassic = Platform{ - names: [2]string{"gcp-classic", "gcp"}, + names: [3]string{"gcp-classic", "gcp"}, } ) @@ -40,6 +40,11 @@ func (plat Platform) String() string { // platform if the provided name isn't supported func ByName(name string) (Platform, error) { normalizedName := strings.TrimSpace(strings.ToLower(name)) + + if normalizedName == "" { + return Platform{}, fmt.Errorf("attempted to lookup Platform with empty string") + } + if slices.Contains(AWSClassic.names[:], normalizedName) { return AWSClassic, nil } diff --git a/pkg/data/cloud/platform_test.go b/pkg/data/cloud/platform_test.go index 204cd8e5..9a54c62f 100644 --- a/pkg/data/cloud/platform_test.go +++ b/pkg/data/cloud/platform_test.go @@ -59,7 +59,7 @@ func TestPlatform_String(t *testing.T) { func TestPlatform_IsValid(t *testing.T) { type fields struct { - names [2]string + names [3]string } tests := []struct { name string @@ -84,7 +84,7 @@ func TestPlatform_IsValid(t *testing.T) { { name: "fake platform", fields: fields{ - names: [2]string{"foo", "bar"}, + names: [3]string{"foo", "bar"}, }, want: false, }, @@ -123,6 +123,10 @@ func TestByName(t *testing.T) { name: "aws-hcp", want: AWSHCP, }, + { + name: "aws-hosted-cp", + want: AWSHCP, + }, { name: "hostedcluster", want: AWSHCP, @@ -139,6 +143,10 @@ func TestByName(t *testing.T) { name: "invalid name", want: Platform{}, }, + { + name: "", + want: Platform{}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {