|
| 1 | +package support |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/onsi/gomega" |
| 9 | +) |
| 10 | + |
| 11 | +func TestGetCodeFlareSDKVersion(t *testing.T) { |
| 12 | + // Set the environment variable. |
| 13 | + os.Setenv(CodeFlareTestSdkVersion, "1.2.3") |
| 14 | + |
| 15 | + // Get the version. |
| 16 | + version := GetCodeFlareSDKVersion() |
| 17 | + |
| 18 | + // Assert that the version is correct. |
| 19 | + if version != "1.2.3" { |
| 20 | + gomega.Expect(version).To(gomega.Equal("1.2.3"), "Expected version 1.2.3, but got %s", version) |
| 21 | + |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +func TestGetRayVersion(t *testing.T) { |
| 26 | + // Set the environment variable. |
| 27 | + os.Setenv(CodeFlareTestRayVersion, "1.4.5") |
| 28 | + |
| 29 | + // Get the version. |
| 30 | + version := GetRayVersion() |
| 31 | + |
| 32 | + // Assert that the version is correct. |
| 33 | + if version != "1.4.5" { |
| 34 | + gomega.Expect(version).To(gomega.Equal("1.2.3"), "Expected version 1.4.5, but got %s", version) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +func TestGetRayImage(t *testing.T) { |
| 39 | + // Set the environment variable. |
| 40 | + os.Setenv(CodeFlareTestRayImage, "ray/ray:latest") |
| 41 | + |
| 42 | + // Get the image. |
| 43 | + image := GetRayImage() |
| 44 | + |
| 45 | + // Assert that the image is correct. |
| 46 | + if image != "ray/ray:latest" { |
| 47 | + gomega.Expect(image).To(gomega.Equal("ray/ray:latest"), "Expected image ray/ray:latest, but got %s", image) |
| 48 | + |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func TestGetPyTorchImage(t *testing.T) { |
| 53 | + // Set the environment variable. |
| 54 | + os.Setenv(CodeFlareTestPyTorchImage, "pytorch/pytorch:latest") |
| 55 | + |
| 56 | + // Get the image. |
| 57 | + image := GetPyTorchImage() |
| 58 | + |
| 59 | + // Assert that the image is correct. |
| 60 | + if image != "pytorch/pytorch:latest" { |
| 61 | + gomega.Expect(image).To(gomega.Equal("pytorch/pytorch:latest"), "Expected image pytorch/pytorch:latest, but got %s", image) |
| 62 | + |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func TestGetClusterID(t *testing.T) { |
| 67 | + os.Setenv(ClusterID, "my-cluster-id") |
| 68 | + clusterId, ok := GetClusterId() |
| 69 | + if !ok { |
| 70 | + gomega.Expect(ok).To(gomega.BeTrue(), "Expected GetClusterId() to return true, but got false.") |
| 71 | + } |
| 72 | + if clusterId != "my-cluster-id" { |
| 73 | + gomega.Expect(clusterId).To(gomega.Equal("my-cluster-id"), "Expected GetClusterId() to return 'my-cluster-id', but got '%s'.", clusterId) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +func TestGetInstascaleOcmSecret(t *testing.T) { |
| 78 | + // Set the Instascale OCM secret environment variable. |
| 79 | + os.Setenv(InstaScaleOcmSecret, "default/instascale-ocm-secret") |
| 80 | + // Get the Instascale OCM secret namespace and secret name. |
| 81 | + namespace, secretName := GetInstascaleOcmSecret() |
| 82 | + |
| 83 | + // Verify that the namespace and secret name are correct. |
| 84 | + if namespace != "default" || secretName != "instascale-ocm-secret" { |
| 85 | + gomega.Expect(fmt.Sprintf("%s/%s", namespace, secretName)).To( |
| 86 | + gomega.Equal("default/instascale-ocm-secret"), |
| 87 | + "Expected GetInstascaleOcmSecret() to return 'default/instascale-ocm-secret', but got '%s/%s'.", |
| 88 | + namespace, secretName, |
| 89 | + ) |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | +} |
| 94 | + |
| 95 | +func TestGetClusterType(t *testing.T) { |
| 96 | + tests := []struct { |
| 97 | + name string |
| 98 | + envVarValue string |
| 99 | + expected ClusterType |
| 100 | + }{ |
| 101 | + { |
| 102 | + name: "OSD cluster", |
| 103 | + envVarValue: "OSD", |
| 104 | + expected: OsdCluster, |
| 105 | + }, |
| 106 | + { |
| 107 | + name: "OCP cluster", |
| 108 | + envVarValue: "OCP", |
| 109 | + expected: OcpCluster, |
| 110 | + }, |
| 111 | + { |
| 112 | + name: "Hypershift cluster", |
| 113 | + envVarValue: "HYPERSHIFT", |
| 114 | + expected: HypershiftCluster, |
| 115 | + }, |
| 116 | + { |
| 117 | + name: "KIND cluster", |
| 118 | + envVarValue: "KIND", |
| 119 | + expected: KindCluster, |
| 120 | + }, |
| 121 | + } |
| 122 | + ttt := With(t) |
| 123 | + for _, tt := range tests { |
| 124 | + t.Run(tt.name, func(t *testing.T) { |
| 125 | + os.Setenv(ClusterTypeEnvVar, tt.envVarValue) |
| 126 | + actual := GetClusterType(ttt) |
| 127 | + if actual != tt.expected { |
| 128 | + gomega.Expect(actual).To( |
| 129 | + gomega.Equal(tt.expected), |
| 130 | + "Expected GetClusterType() to return %v, but got %v", tt.expected, actual, |
| 131 | + ) |
| 132 | + |
| 133 | + } |
| 134 | + }) |
| 135 | + } |
| 136 | +} |
0 commit comments