Skip to content

Commit bfa125e

Browse files
authored
Fix potential issue in odo version nightly tests if user does not have permission to get the OpenShift version (#6933)
* Fix issues in the tests if user does not have permission to see the OpenShift platform version This happened on the nightly jobs running on Prow, which makes us use a developer account with some restrictions. * Rename 'helper.JsonSatisfies' into 'helper.JsonStatisfiesAll' to make the intent clearer
1 parent 94e3230 commit bfa125e

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

tests/helper/helper_generic.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"github.com/onsi/gomega/types"
98
"os"
109
"path/filepath"
1110
"regexp"
@@ -15,6 +14,8 @@ import (
1514
"testing"
1615
"time"
1716

17+
"github.com/onsi/gomega/types"
18+
1819
"github.com/tidwall/gjson"
1920

2021
"github.com/redhat-developer/odo/pkg/config"
@@ -325,8 +326,8 @@ func JsonPathContentContain(json string, path string, value string) {
325326
Expect(result.String()).To(ContainSubstring(value), fmt.Sprintf("content of path %q should contain %q but is %q", path, value, result.String()))
326327
}
327328

328-
// JsonPathSatisfies expects content of the path to satisfy all the matchers passed to it
329-
func JsonPathSatisfies(json string, path string, matchers ...types.GomegaMatcher) {
329+
// JsonPathSatisfiesAll expects content of the path to satisfy all the matchers passed to it
330+
func JsonPathSatisfiesAll(json string, path string, matchers ...types.GomegaMatcher) {
330331
result := gjson.Get(json, path)
331332
Expect(result.String()).Should(SatisfyAll(matchers...))
332333
}

tests/integration/generic_test.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package integration
33
import (
44
. "github.com/onsi/ginkgo/v2"
55
. "github.com/onsi/gomega"
6+
67
"github.com/redhat-developer/odo/tests/helper"
78
)
89

@@ -141,24 +142,34 @@ var _ = Describe("odo generic", func() {
141142
serverURL := oc.GetCurrentServerURL()
142143
Expect(odoVersion).Should(ContainSubstring("Server: " + serverURL))
143144
if !helper.IsKubernetesCluster() {
144-
Expect(odoVersion).Should(ContainSubstring("OpenShift: "))
145+
ocpMatcher := ContainSubstring("OpenShift: ")
146+
if serverVersion := commonVar.CliRunner.GetVersion(); serverVersion == "" {
147+
// Might indicate a user permission error on certain clusters (observed with a developer account on Prow nightly jobs)
148+
ocpMatcher = Not(ocpMatcher)
149+
}
150+
Expect(odoVersion).Should(ocpMatcher)
145151
}
146152
}
147153
})
148154

149155
By("checking the JSON output", func() {
150156
odoVersion = helper.Cmd("odo", "version", "-o", "json").ShouldPass().Out()
151157
Expect(helper.IsJSON(odoVersion)).To(BeTrue())
152-
helper.JsonPathSatisfies(odoVersion, "version", MatchRegexp(reJSONVersion))
158+
helper.JsonPathSatisfiesAll(odoVersion, "version", MatchRegexp(reJSONVersion))
153159
helper.JsonPathExist(odoVersion, "gitCommit")
154160
if podman {
155-
helper.JsonPathSatisfies(odoVersion, "podman.client.version", MatchRegexp(reJSONVersion), Equal(helper.GetPodmanVersion()))
161+
helper.JsonPathSatisfiesAll(odoVersion, "podman.client.version", MatchRegexp(reJSONVersion), Equal(helper.GetPodmanVersion()))
156162
} else {
157-
helper.JsonPathSatisfies(odoVersion, "cluster.kubernetes.version", MatchRegexp(reJSONVersion))
163+
helper.JsonPathSatisfiesAll(odoVersion, "cluster.kubernetes.version", MatchRegexp(reJSONVersion))
158164
serverURL := oc.GetCurrentServerURL()
159165
helper.JsonPathContentIs(odoVersion, "cluster.serverURL", serverURL)
160166
if !helper.IsKubernetesCluster() {
161-
helper.JsonPathSatisfies(odoVersion, "cluster.openshift", Not(BeEmpty()))
167+
m := BeEmpty()
168+
if serverVersion := commonVar.CliRunner.GetVersion(); serverVersion != "" {
169+
// A blank serverVersion might indicate a user permission error on certain clusters (observed with a developer account on Prow nightly jobs)
170+
m = Not(m)
171+
}
172+
helper.JsonPathSatisfiesAll(odoVersion, "cluster.openshift", m)
162173
}
163174
}
164175
})
@@ -194,10 +205,10 @@ var _ = Describe("odo generic", func() {
194205
By("checking JSON output", func() {
195206
odoVersion := helper.Cmd("odo", "version", "--client", "-o", "json").ShouldPass().Out()
196207
Expect(helper.IsJSON(odoVersion)).To(BeTrue())
197-
helper.JsonPathSatisfies(odoVersion, "version", MatchRegexp(reJSONVersion))
208+
helper.JsonPathSatisfiesAll(odoVersion, "version", MatchRegexp(reJSONVersion))
198209
helper.JsonPathExist(odoVersion, "gitCommit")
199-
helper.JsonPathSatisfies(odoVersion, "cluster", BeEmpty())
200-
helper.JsonPathSatisfies(odoVersion, "podman", BeEmpty())
210+
helper.JsonPathSatisfiesAll(odoVersion, "cluster", BeEmpty())
211+
helper.JsonPathSatisfiesAll(odoVersion, "podman", BeEmpty())
201212
})
202213
})
203214
})

0 commit comments

Comments
 (0)