Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSD-25868: Adds aws-hosted-cp as a valid Platform name #275

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pkg/data/cloud/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
)

Expand All @@ -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
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/data/cloud/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
Expand Down Expand Up @@ -123,6 +123,10 @@ func TestByName(t *testing.T) {
name: "aws-hcp",
want: AWSHCP,
},
joshbranham marked this conversation as resolved.
Show resolved Hide resolved
{
name: "aws-hosted-cp",
want: AWSHCP,
},
{
name: "hostedcluster",
want: AWSHCP,
Expand All @@ -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) {
Expand Down