Skip to content

Commit

Permalink
OSD-25868: Adds aws-hosted-cp as a valid Platform name (#275)
Browse files Browse the repository at this point in the history
* OSD-25868: Adds `aws-hosted-cp` as a valid Platform name
This extends the Platform structs to accept `aws-hosted-cp` as a valid value for looking up
AWSHCP `ByName()`. This value is used internally still and blocks integrating the updated
verifier.

* Handle empty string lookups as an error
  • Loading branch information
joshbranham authored Oct 3, 2024
1 parent 047bd06 commit 30238fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
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,
},
{
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

0 comments on commit 30238fb

Please sign in to comment.