Skip to content
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

Fix potential issue in odo version nightly tests if user does not have permission to get the OpenShift version #6933

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions tests/helper/helper_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/onsi/gomega/types"
"os"
"path/filepath"
"regexp"
Expand All @@ -15,6 +14,8 @@ import (
"testing"
"time"

"github.com/onsi/gomega/types"

"github.com/tidwall/gjson"

"github.com/redhat-developer/odo/pkg/config"
Expand Down Expand Up @@ -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...))
}
Expand Down
27 changes: 19 additions & 8 deletions tests/integration/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integration
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/redhat-developer/odo/tests/helper"
)

Expand Down Expand Up @@ -141,24 +142,34 @@ 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)
}
}
})

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() {
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.JsonPathSatisfiesAll(odoVersion, "cluster.openshift", m)
}
}
})
Expand Down Expand Up @@ -194,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())
})
})
})
Expand Down