From 12f1f5649d300f8a4f4dbc4a8ffb7210776c3691 Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Mon, 26 Jun 2023 16:35:35 +0200 Subject: [PATCH 1/2] 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. --- tests/integration/generic_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/integration/generic_test.go b/tests/integration/generic_test.go index 4a03c015875..bf7e2d07bdf 100644 --- a/tests/integration/generic_test.go +++ b/tests/integration/generic_test.go @@ -3,6 +3,7 @@ package integration import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/redhat-developer/odo/tests/helper" ) @@ -141,7 +142,12 @@ var _ = Describe("odo generic", func() { serverURL := oc.GetCurrentServerURL() Expect(odoVersion).Should(ContainSubstring("Server: " + serverURL)) if !helper.IsKubernetesCluster() { - Expect(odoVersion).Should(ContainSubstring("OpenShift: ")) + ocpMatcher := ContainSubstring("OpenShift: ") + if serverVersion := commonVar.CliRunner.GetVersion(); serverVersion == "" { + // Might indicate a user permission error on certain clusters (observed with a developer account on Prow nightly jobs) + ocpMatcher = Not(ocpMatcher) + } + Expect(odoVersion).Should(ocpMatcher) } } }) @@ -158,7 +164,12 @@ var _ = Describe("odo generic", func() { serverURL := oc.GetCurrentServerURL() helper.JsonPathContentIs(odoVersion, "cluster.serverURL", serverURL) if !helper.IsKubernetesCluster() { - helper.JsonPathSatisfies(odoVersion, "cluster.openshift", Not(BeEmpty())) + m := BeEmpty() + if serverVersion := commonVar.CliRunner.GetVersion(); serverVersion != "" { + // A blank serverVersion might indicate a user permission error on certain clusters (observed with a developer account on Prow nightly jobs) + m = Not(m) + } + helper.JsonPathSatisfies(odoVersion, "cluster.openshift", m) } } }) From 6a2f36a5378ba455e9689e28554279b70d1002da Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Mon, 26 Jun 2023 16:37:22 +0200 Subject: [PATCH 2/2] Rename 'helper.JsonSatisfies' into 'helper.JsonStatisfiesAll' to make the intent clearer --- tests/helper/helper_generic.go | 7 ++++--- tests/integration/generic_test.go | 14 +++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/helper/helper_generic.go b/tests/helper/helper_generic.go index f0c0880a79a..d0d8cd5f60a 100644 --- a/tests/helper/helper_generic.go +++ b/tests/helper/helper_generic.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/onsi/gomega/types" "os" "path/filepath" "regexp" @@ -15,6 +14,8 @@ import ( "testing" "time" + "github.com/onsi/gomega/types" + "github.com/tidwall/gjson" "github.com/redhat-developer/odo/pkg/config" @@ -325,8 +326,8 @@ func JsonPathContentContain(json string, path string, value string) { Expect(result.String()).To(ContainSubstring(value), fmt.Sprintf("content of path %q should contain %q but is %q", path, value, result.String())) } -// JsonPathSatisfies expects content of the path to satisfy all the matchers passed to it -func JsonPathSatisfies(json string, path string, matchers ...types.GomegaMatcher) { +// JsonPathSatisfiesAll expects content of the path to satisfy all the matchers passed to it +func JsonPathSatisfiesAll(json string, path string, matchers ...types.GomegaMatcher) { result := gjson.Get(json, path) Expect(result.String()).Should(SatisfyAll(matchers...)) } diff --git a/tests/integration/generic_test.go b/tests/integration/generic_test.go index bf7e2d07bdf..f5f98632c0a 100644 --- a/tests/integration/generic_test.go +++ b/tests/integration/generic_test.go @@ -155,12 +155,12 @@ var _ = Describe("odo generic", func() { By("checking the JSON output", func() { odoVersion = helper.Cmd("odo", "version", "-o", "json").ShouldPass().Out() Expect(helper.IsJSON(odoVersion)).To(BeTrue()) - helper.JsonPathSatisfies(odoVersion, "version", MatchRegexp(reJSONVersion)) + helper.JsonPathSatisfiesAll(odoVersion, "version", MatchRegexp(reJSONVersion)) helper.JsonPathExist(odoVersion, "gitCommit") if podman { - helper.JsonPathSatisfies(odoVersion, "podman.client.version", MatchRegexp(reJSONVersion), Equal(helper.GetPodmanVersion())) + helper.JsonPathSatisfiesAll(odoVersion, "podman.client.version", MatchRegexp(reJSONVersion), Equal(helper.GetPodmanVersion())) } else { - helper.JsonPathSatisfies(odoVersion, "cluster.kubernetes.version", MatchRegexp(reJSONVersion)) + helper.JsonPathSatisfiesAll(odoVersion, "cluster.kubernetes.version", MatchRegexp(reJSONVersion)) serverURL := oc.GetCurrentServerURL() helper.JsonPathContentIs(odoVersion, "cluster.serverURL", serverURL) if !helper.IsKubernetesCluster() { @@ -169,7 +169,7 @@ var _ = Describe("odo generic", func() { // A blank serverVersion might indicate a user permission error on certain clusters (observed with a developer account on Prow nightly jobs) m = Not(m) } - helper.JsonPathSatisfies(odoVersion, "cluster.openshift", m) + helper.JsonPathSatisfiesAll(odoVersion, "cluster.openshift", m) } } }) @@ -205,10 +205,10 @@ var _ = Describe("odo generic", func() { By("checking JSON output", func() { odoVersion := helper.Cmd("odo", "version", "--client", "-o", "json").ShouldPass().Out() Expect(helper.IsJSON(odoVersion)).To(BeTrue()) - helper.JsonPathSatisfies(odoVersion, "version", MatchRegexp(reJSONVersion)) + helper.JsonPathSatisfiesAll(odoVersion, "version", MatchRegexp(reJSONVersion)) helper.JsonPathExist(odoVersion, "gitCommit") - helper.JsonPathSatisfies(odoVersion, "cluster", BeEmpty()) - helper.JsonPathSatisfies(odoVersion, "podman", BeEmpty()) + helper.JsonPathSatisfiesAll(odoVersion, "cluster", BeEmpty()) + helper.JsonPathSatisfiesAll(odoVersion, "podman", BeEmpty()) }) }) })