Skip to content

Commit da8c04c

Browse files
sutaakarFiona-Waters
authored andcommitted
Use enum for cluster type in e2e tests
1 parent 3e187a3 commit da8c04c

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

test/e2e/instascale_machineset_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ func TestInstascaleMachineSet(t *testing.T) {
1414
test.T().Parallel()
1515

1616
// skip test if not using machine sets
17-
clusterType := DetermineClusterType()
17+
clusterType := GetClusterType(test)
1818
if clusterType != OcpCluster {
19-
test.T().Skip("Skipping test as not running on an OCP cluster")
19+
test.T().Skipf("Skipping test as not running on an OCP cluster, resolved cluster type: %s", clusterType)
2020
}
2121

2222
namespace := test.NewTestNamespace()

test/support/environment.go

+27-26
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ const (
4040
OsdClusterID = "CLUSTERID"
4141

4242
// Type of cluster test is run on
43-
ClusterType = "CLUSTER_TYPE"
44-
// OpenShift Dedicated Cluster
45-
OsdCluster = "OSD"
46-
// OpenShift Container Platform Cluster
47-
OcpCluster = "OCP"
48-
// ROSA Hosted Hypershift Cluster
49-
HypershiftCluster = "HYPERSHIFT"
43+
ClusterTypeEnvVar = "CLUSTER_TYPE"
44+
)
45+
46+
type ClusterType string
47+
48+
const (
49+
OsdCluster ClusterType = "OSD"
50+
OcpCluster ClusterType = "OCP"
51+
HypershiftCluster ClusterType = "HYPERSHIFT"
52+
UndefinedCluster ClusterType = "UNDEFINED"
5053
)
5154

5255
func GetCodeFlareSDKVersion() string {
@@ -74,8 +77,23 @@ func GetOsdClusterId() (string, bool) {
7477
return os.LookupEnv(OsdClusterID)
7578
}
7679

77-
func GetClusterType() (string, bool) {
78-
return os.LookupEnv(ClusterType)
80+
func GetClusterType(t Test) ClusterType {
81+
clusterType, ok := os.LookupEnv(ClusterTypeEnvVar)
82+
if !ok {
83+
t.T().Logf("Expected environment variable %s not found, cluster type is not defined.", ClusterTypeEnvVar)
84+
return UndefinedCluster
85+
}
86+
switch clusterType {
87+
case "OSD":
88+
return OsdCluster
89+
case "OCP":
90+
return OcpCluster
91+
case "HYPERSHIFT":
92+
return HypershiftCluster
93+
default:
94+
t.T().Logf("Expected environment variable %s contains unexpected value: '%s'", ClusterTypeEnvVar, clusterType)
95+
return UndefinedCluster
96+
}
7997
}
8098

8199
func IsOsd() bool {
@@ -92,20 +110,3 @@ func lookupEnvOrDefault(key, value string) string {
92110
}
93111
return value
94112
}
95-
96-
func DetermineClusterType() string {
97-
clusterType, ok := GetClusterType()
98-
if !ok {
99-
return ""
100-
}
101-
switch clusterType {
102-
case "OSD":
103-
return OsdCluster
104-
case "OCP":
105-
return OcpCluster
106-
case "HYPERSHIFT":
107-
return HypershiftCluster
108-
default:
109-
return ""
110-
}
111-
}

0 commit comments

Comments
 (0)