Skip to content

Add unit tests for support package #13

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

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
30ae434
Add unit tests for support package
Raghul-M Nov 20, 2023
51f2ab2
Merge branch 'unittestsupport#239' of github.com:Raghul-M/codeflare-c…
Raghul-M Nov 20, 2023
ec26208
Add unit tests for support package
Raghul-M Nov 20, 2023
7a3ef44
Add unit tests for support package
Raghul-M Nov 20, 2023
156eb48
Fixed Changes in Comments and added Ingress_test
Raghul-M Nov 21, 2023
cd87d08
Fixed Make Imports Failure
Raghul-M Nov 21, 2023
181f8e0
Made Changes and added image_test.go
Raghul-M Nov 28, 2023
af39294
Added: Machine_test.go
Raghul-M Nov 29, 2023
79b9c56
Added route_test.go
Raghul-M Dec 7, 2023
75624a2
Added route_test.go
Raghul-M Dec 7, 2023
c900833
Added TestGetRayCluster
Raghul-M Dec 11, 2023
f7e8390
Added core_test.go and Modified batch_test.go
Raghul-M Dec 18, 2023
b7de453
Modified code for Actions failed
Raghul-M Dec 18, 2023
8e9c140
Add unit tests for support package
Raghul-M Nov 20, 2023
97ff393
Add unit tests for support package
Raghul-M Nov 20, 2023
f99160f
Add unit tests for support package
Raghul-M Nov 20, 2023
f20180c
Fixed Changes in Comments and added Ingress_test
Raghul-M Nov 21, 2023
9ece9d0
Fixed Make Imports Failure
Raghul-M Nov 21, 2023
2909449
Made Changes and added image_test.go
Raghul-M Nov 28, 2023
6f531c5
Added: Machine_test.go
Raghul-M Nov 29, 2023
1801e8f
Added route_test.go
Raghul-M Dec 7, 2023
49cc6d7
Added route_test.go
Raghul-M Dec 7, 2023
8328226
Added TestGetRayCluster
Raghul-M Dec 11, 2023
3b3b8b1
Added core_test.go and Modified batch_test.go
Raghul-M Dec 18, 2023
320ebaa
Modified code for Actions failed
Raghul-M Dec 18, 2023
4b870a8
Made PR Checks issues clearance
Raghul-M Dec 26, 2023
d96697b
Cleared Merge conflicts
Raghul-M Dec 26, 2023
87da9cd
Updated code
Raghul-M Jan 2, 2024
3dae5d6
Merge remote-tracking branch 'origin/main' into unittestsupport#239
Raghul-M Jan 2, 2024
7310aae
Updated code
Raghul-M Jan 2, 2024
ffd54b2
Resolved Merge Conflicts
Raghul-M Jan 2, 2024
9c552ad
Resolved Merge Conflicts
Raghul-M Jan 2, 2024
83832c9
Generalized Fakeclient
Raghul-M Jan 3, 2024
369b325
Final Commit for PR Merge
Raghul-M Jan 3, 2024
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
24 changes: 24 additions & 0 deletions .github/workflows/verify_unit_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Verify Unit tests

on:
pull_request:
paths:
- 'support/**'

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: v1.19


- name: Run unit tests
run: go test ./support/. -v

8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ require (
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c
github.com/project-codeflare/multi-cluster-app-dispatcher v1.37.0
github.com/ray-project/kuberay/ray-operator v0.0.0-20231016183545-097828931d15
github.com/stretchr/testify v1.8.4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is testify used for?

Copy link
Contributor Author

@Raghul-M Raghul-M Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed running go mod tidy . testify It's not needed.

k8s.io/api v0.26.3
k8s.io/apimachinery v0.26.3
k8s.io/client-go v0.26.3
sigs.k8s.io/controller-runtime v0.14.6
)

require (
Expand All @@ -21,6 +23,8 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
Expand All @@ -43,11 +47,14 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.10.0 // indirect
Expand All @@ -62,7 +69,6 @@ require (
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d // indirect
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect
sigs.k8s.io/controller-runtime v0.14.6 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
12 changes: 11 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww=
github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand All @@ -100,6 +102,7 @@ github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KE
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A=
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8=
Expand Down Expand Up @@ -378,6 +381,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand All @@ -387,7 +391,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
Expand All @@ -407,13 +412,16 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
Expand Down Expand Up @@ -658,6 +666,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
Expand Down Expand Up @@ -778,6 +787,7 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.26.3 h1:emf74GIQMTik01Aum9dPP0gAypL8JTLl/lHa4V9RFSU=
k8s.io/api v0.26.3/go.mod h1:PXsqwPMXBSBcL1lJ9CYDKy7kIReUydukS5JiRlxC3qE=
k8s.io/apiextensions-apiserver v0.26.1 h1:cB8h1SRk6e/+i3NOrQgSFij1B2S0Y0wDoNl66bn8RMI=
k8s.io/apimachinery v0.26.3 h1:dQx6PNETJ7nODU3XPtrwkfuubs6w7sX0M8n61zHIV/k=
k8s.io/apimachinery v0.26.3/go.mod h1:ats7nN1LExKHvJ9TmwootT00Yz05MuYqPXEXaVeOy5I=
k8s.io/client-go v0.26.3 h1:k1UY+KXfkxV2ScEL3gilKcF7761xkYsSD6BC9szIu8s=
Expand Down
55 changes: 55 additions & 0 deletions support/batch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2023.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package support

import (
"testing"

"github.com/onsi/gomega"

batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

func TestGetJob(t *testing.T) {

g := gomega.NewGomegaWithT(t)

fakeJobs := []runtime.Object{
&batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "my-job-1",
Namespace: "my-namespace",
},
},
}
fakeClient := NewFakeKubeClientWithObjects(fakeJobs...)

test := With(t).(*T)
test.client = &testClient{
core: fakeClient,
}

// Call the Job function using the fake client
jobFunc := Job(test, "my-namespace", "my-job-1")
job := jobFunc(g)

g.Expect(job.Name).To(gomega.Equal("my-job-1"))
g.Expect(job.Namespace).To(gomega.Equal("my-namespace"))

}
51 changes: 51 additions & 0 deletions support/core_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package support

import (
"testing"

"github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
)

func TestGetPods(t *testing.T) {
// Create a fake Kubernetes client for testing
fakeClient := fake.NewSimpleClientset(&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod",
Namespace: "test-namespace",
},
})

test := With(t).(*T)
test.client = &testClient{
core: fakeClient,
}

// Call the GetPods function with the fake client and namespace
pods := GetPods(test, "test-namespace", metav1.ListOptions{})

test.Expect(pods).Should(gomega.HaveLen(1), "Expected 1 pod, but got %d", len(pods))
test.Expect(pods[0].Name).To(gomega.Equal("test-pod"), "Expected pod name 'test-pod', but got '%s'", pods[0].Name)
}

func TestGetNodes(t *testing.T) {
// Create a fake Kubernetes client for testing
fakeClient := fake.NewSimpleClientset(&corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node",
},
})

test := With(t).(*T)
test.client = &testClient{
core: fakeClient,
}
nodes := GetNodes(test)

test.Expect(nodes).Should(gomega.HaveLen(1), "Expected 1 node, but got %d", len(nodes))
test.Expect(nodes[0].Name).To(gomega.Equal("test-node"), "Expected node name 'test-node', but got '%s'", nodes[0].Name)

}
136 changes: 136 additions & 0 deletions support/environment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package support

import (
"fmt"
"os"
"testing"

"github.com/onsi/gomega"
)

func TestGetCodeFlareSDKVersion(t *testing.T) {
// Set the environment variable.
os.Setenv(CodeFlareTestSdkVersion, "1.2.3")

// Get the version.
version := GetCodeFlareSDKVersion()

// Assert that the version is correct.
if version != "1.2.3" {
gomega.Expect(version).To(gomega.Equal("1.2.3"), "Expected version 1.2.3, but got %s", version)

}
}

func TestGetRayVersion(t *testing.T) {
// Set the environment variable.
os.Setenv(CodeFlareTestRayVersion, "1.4.5")

// Get the version.
version := GetRayVersion()

// Assert that the version is correct.
if version != "1.4.5" {
gomega.Expect(version).To(gomega.Equal("1.2.3"), "Expected version 1.4.5, but got %s", version)
}
}

func TestGetRayImage(t *testing.T) {
// Set the environment variable.
os.Setenv(CodeFlareTestRayImage, "ray/ray:latest")

// Get the image.
image := GetRayImage()

// Assert that the image is correct.
if image != "ray/ray:latest" {
gomega.Expect(image).To(gomega.Equal("ray/ray:latest"), "Expected image ray/ray:latest, but got %s", image)

}
}

func TestGetPyTorchImage(t *testing.T) {
// Set the environment variable.
os.Setenv(CodeFlareTestPyTorchImage, "pytorch/pytorch:latest")

// Get the image.
image := GetPyTorchImage()

// Assert that the image is correct.
if image != "pytorch/pytorch:latest" {
gomega.Expect(image).To(gomega.Equal("pytorch/pytorch:latest"), "Expected image pytorch/pytorch:latest, but got %s", image)

}
}

func TestGetClusterID(t *testing.T) {
os.Setenv(ClusterID, "my-cluster-id")
clusterId, ok := GetClusterId()
if !ok {
gomega.Expect(ok).To(gomega.BeTrue(), "Expected GetClusterId() to return true, but got false.")
}
if clusterId != "my-cluster-id" {
gomega.Expect(clusterId).To(gomega.Equal("my-cluster-id"), "Expected GetClusterId() to return 'my-cluster-id', but got '%s'.", clusterId)
}
}

func TestGetInstascaleOcmSecret(t *testing.T) {
// Set the Instascale OCM secret environment variable.
os.Setenv(InstaScaleOcmSecret, "default/instascale-ocm-secret")
// Get the Instascale OCM secret namespace and secret name.
namespace, secretName := GetInstascaleOcmSecret()

// Verify that the namespace and secret name are correct.
if namespace != "default" || secretName != "instascale-ocm-secret" {
gomega.Expect(fmt.Sprintf("%s/%s", namespace, secretName)).To(
gomega.Equal("default/instascale-ocm-secret"),
"Expected GetInstascaleOcmSecret() to return 'default/instascale-ocm-secret', but got '%s/%s'.",
namespace, secretName,
)

}

}

func TestGetClusterType(t *testing.T) {
tests := []struct {
name string
envVarValue string
expected ClusterType
}{
{
name: "OSD cluster",
envVarValue: "OSD",
expected: OsdCluster,
},
{
name: "OCP cluster",
envVarValue: "OCP",
expected: OcpCluster,
},
{
name: "Hypershift cluster",
envVarValue: "HYPERSHIFT",
expected: HypershiftCluster,
},
{
name: "KIND cluster",
envVarValue: "KIND",
expected: KindCluster,
},
}
ttt := With(t)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
os.Setenv(ClusterTypeEnvVar, tt.envVarValue)
actual := GetClusterType(ttt)
if actual != tt.expected {
gomega.Expect(actual).To(
gomega.Equal(tt.expected),
"Expected GetClusterType() to return %v, but got %v", tt.expected, actual,
)

}
})
}
}
Loading