@@ -2,6 +2,8 @@ package env
22
33import (
44 "testing"
5+
6+ "github.com/stretchr/testify/assert"
57)
68
79func TestDetectClusterType_GKE (t * testing.T ) {
@@ -40,7 +42,7 @@ func TestDetectClusterType_GKE_ExactMatch(t *testing.T) {
4042 }
4143}
4244
43- func TestDetectClusterType_OpenShift4 (t * testing.T ) {
45+ func TestDetectClusterType_InfraOpenShift4 (t * testing.T ) {
4446 config := KubeConfig {
4547 CurrentContext : "admin" ,
4648 Clusters : []KubeCluster {
@@ -58,31 +60,28 @@ func TestDetectClusterType_OpenShift4(t *testing.T) {
5860 }
5961
6062 result := detectClusterType (config , apiResources )
61- if result != InfraOpenShift4 {
62- t .Errorf ("detectClusterType() = %v (%s), want %v (%s)" , result , result .String (), InfraOpenShift4 , InfraOpenShift4 .String ())
63- }
63+ assert .Equal (t , InfraOpenShift4 , result )
6464}
6565
66- func TestDetectClusterType_OpenShift4_WrongHostname (t * testing.T ) {
66+ func TestDetectClusterType_OpenShift4 (t * testing.T ) {
6767 config := KubeConfig {
68- CurrentContext : "admin " ,
68+ CurrentContext : "some-context-name " ,
6969 Clusters : []KubeCluster {
7070 {
71- Name : "openshift-cluster " ,
72- Server : "https://api. my-cluster.example.com:6443" ,
71+ Name : "some-other-name " ,
72+ Server : "https://my-cluster.example.com:6443" ,
7373 },
7474 },
7575 }
7676 apiResources := []string {
7777 "pods" ,
7878 "services" ,
7979 "clusterversions.config.openshift.io" ,
80+ "clusteroperators.config.openshift.io" ,
8081 }
8182
8283 result := detectClusterType (config , apiResources )
83- if result != ClusterTypeUnknown {
84- t .Errorf ("detectClusterType() = %v (%s), want %v (%s)" , result , result .String (), ClusterTypeUnknown , ClusterTypeUnknown .String ())
85- }
84+ assert .Equal (t , OpenShift4 , result )
8685}
8786
8887func TestDetectClusterType_OpenShift4_NoAPIResources (t * testing.T ) {
@@ -295,6 +294,11 @@ func TestClusterTypeString(t *testing.T) {
295294 {
296295 name : "InfraOpenShift4" ,
297296 clusterType : InfraOpenShift4 ,
297+ want : "OpenShift4 (infra)" ,
298+ },
299+ {
300+ name : "OpenShift4" ,
301+ clusterType : OpenShift4 ,
298302 want : "OpenShift4" ,
299303 },
300304 {
0 commit comments