Skip to content

Commit 95a83b6

Browse files
committed
Changed 1-031_validate_toolchain_test.go to use yaml snapshot of the versions to make checking an updating easier.
If env-var E2E_UPDATE_SNAPSHOTS=1 is present, the file will autoupdate. Assisted-by: Claude <usersafety@anthropic.com> Signed-off-by: Adam Saleh <adam@asaleh.net>
1 parent fa6f4ab commit 95a83b6

3 files changed

Lines changed: 52 additions & 30 deletions

File tree

test/openshift/e2e/ginkgo/parallel/1-031_validate_toolchain_test.go

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ package parallel
1919
import (
2020
"context"
2121
"os"
22-
23-
// "os"
24-
22+
"path/filepath"
2523
"strings"
2624
"time"
2725

@@ -35,6 +33,7 @@ import (
3533
corev1 "k8s.io/api/core/v1"
3634
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3735
"k8s.io/apimachinery/pkg/util/wait"
36+
"sigs.k8s.io/yaml"
3837

3938
"sigs.k8s.io/controller-runtime/pkg/client"
4039
)
@@ -84,25 +83,6 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
8483

8584
It("verifies that toolchain versions have the expected values", func() {
8685

87-
// These variables need to be maintained according to the component matrix: https://spaces.redhat.com/display/GITOPS/GitOps+Component+Matrix
88-
expected_kustomizeVersion := "v5.8.0"
89-
expected_helmVersion := "v3.19.4"
90-
expected_argocdVersion := "v3.3.0"
91-
92-
var expected_dexVersion string
93-
var expected_redisVersion string
94-
95-
if os.Getenv("CI") == "prow" {
96-
// when running against openshift-ci
97-
expected_dexVersion = "v2.43.0"
98-
expected_redisVersion = "8.2.3"
99-
100-
} else {
101-
// when running against RC/ released version of gitops
102-
expected_dexVersion = "v2.43.1"
103-
expected_redisVersion = "7.2.11"
104-
}
105-
10686
By("locating pods containing toolchain in openshift-gitops")
10787

10888
gitops_server_pod, err := getPodName("openshift-gitops-server")
@@ -142,6 +122,17 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
142122
// argocd-server: v2.13.1+af54ef8
143123
Expect(err).NotTo(HaveOccurred())
144124

125+
// Extract the version from "argocd-server: v3.3.0+af54ef8" and strip the +<hash> suffix,
126+
// since the test intent is to match the base version only (ContainSubstring was used previously for this reason).
127+
argocdVersionLine := strings.TrimSpace(argocdVersion)
128+
argocdVersionClean := argocdVersionLine
129+
if idx := strings.LastIndex(argocdVersionLine, " "); idx != -1 {
130+
argocdVersionClean = argocdVersionLine[idx+1:]
131+
}
132+
if idx := strings.Index(argocdVersionClean, "+"); idx != -1 {
133+
argocdVersionClean = argocdVersionClean[:idx]
134+
}
135+
145136
By("extracting the dex version from container")
146137
dexVersionOutput, err := osFixture.ExecCommand("bash", "-c", "oc -n openshift-gitops exec "+dex_pod+" -- dex version")
147138
Expect(err).ToNot(HaveOccurred())
@@ -172,17 +163,38 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
172163
// After: v=6.2.7
173164
Expect(err).NotTo(HaveOccurred())
174165

175-
By("verifying containers have expected toolchain versions")
166+
By("collecting all toolchain versions")
167+
168+
collectedVersions := map[string]string{
169+
"argocd": argocdVersionClean,
170+
"dex": dexVersion,
171+
"helm": helmVersion,
172+
"kustomize": kustomizeVersion,
173+
"redis": redisVersion,
174+
}
175+
176+
snapshotPath := "../snapshots/valid_toolchain_versions_release.yaml"
177+
if os.Getenv("CI") == "prow" {
178+
snapshotPath = "../snapshots/valid_toolchain_versions_prow.yaml"
179+
}
180+
181+
if os.Getenv("E2E_UPDATE_SNAPSHOTS") == "1" {
182+
By("updating snapshot file with collected versions")
183+
data, marshalErr := yaml.Marshal(collectedVersions)
184+
Expect(marshalErr).NotTo(HaveOccurred())
185+
Expect(os.MkdirAll(filepath.Dir(snapshotPath), 0755)).To(Succeed())
186+
Expect(os.WriteFile(snapshotPath, data, 0644)).To(Succeed())
187+
}
188+
189+
By("comparing collected versions against snapshot")
176190

177-
Expect(kustomizeVersion).To(Equal(expected_kustomizeVersion))
178-
Expect(helmVersion).To(Equal(expected_helmVersion))
179-
Expect(dexVersion).To(Equal(expected_dexVersion))
191+
snapshotData, readErr := os.ReadFile(snapshotPath)
192+
Expect(readErr).NotTo(HaveOccurred(), "snapshot file not found at %s; run with E2E_UPDATE_SNAPSHOTS=1 to create it", snapshotPath)
180193

181-
// We are as argocdVersion contains v2.7.6+00c914a suffix addition to the version no.
182-
// So, we are checking if expected_argocdVersion is substring of the actual version
183-
Expect(argocdVersion).To(ContainSubstring(expected_argocdVersion))
194+
var snapshotVersions map[string]string
195+
Expect(yaml.Unmarshal(snapshotData, &snapshotVersions)).To(Succeed())
184196

185-
Expect(redisVersion).To(Equal(expected_redisVersion))
197+
Expect(collectedVersions).To(Equal(snapshotVersions))
186198

187199
})
188200

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
argocd: v3.3.2
2+
dex: v2.43.0
3+
helm: v3.19.4
4+
kustomize: v5.8.1
5+
redis: 7.2.11
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
argocd: v3.3.2
2+
dex: v2.43.0
3+
helm: v3.19.4
4+
kustomize: v5.8.1
5+
redis: 7.2.11

0 commit comments

Comments
 (0)