Test with OpenShift cluster non authenticated (#6395)

* Test with OpenShift cluster non authenticated

* Add analyze commands

* Add same tests as with NoCluster

* Do not try to cleanup namespaces

* Assert non authenticated

* Change Makefile target name
This commit is contained in:
Philippe Martin
2022-12-09 12:41:38 +01:00
committed by GitHub
parent 6c99ca1024
commit 83cdda6960
18 changed files with 1687 additions and 1540 deletions

View File

@@ -0,0 +1,21 @@
#!/bin/bash
LOGFILE="pr-${GIT_PR_NUMBER}-openshift-tests-${BUILD_NUMBER}"
source .ibm/pipelines/functions.sh
ibmcloud login --apikey "${API_KEY_QE}"
ibmcloud target -r eu-de
ibmcloud oc cluster config -c "${CLUSTER_ID}"
(
set -e
make install
make test-integration-openshift-unauth
) |& tee "/tmp/${LOGFILE}"
RESULT=${PIPESTATUS[0]}
save_logs "${LOGFILE}" "OpenShift Unauthenticated Tests" ${RESULT}
exit ${RESULT}

View File

@@ -192,7 +192,11 @@ openshiftci-presubmit-unittests:
.PHONY: test-integration-cluster
test-integration-cluster:
$(RUN_GINKGO) $(GINKGO_FLAGS) --junit-report="test-integration.xml" --label-filter="!nocluster && !podman" tests/integration
$(RUN_GINKGO) $(GINKGO_FLAGS) --junit-report="test-integration.xml" --label-filter="!unauth && !nocluster && !podman" tests/integration
.PHONY: test-integration-openshift-unauth
test-integration-openshift-unauth:
$(RUN_GINKGO) $(GINKGO_FLAGS) --junit-report="test-integration-unauth.xml" --label-filter="unauth" tests/integration
.PHONY: test-integration-no-cluster
test-integration-no-cluster:

View File

@@ -56,4 +56,5 @@ type CliRunner interface {
AssertContainsLabel(kind, namespace, componentName, appName, mode, key, value string)
AssertNoContainsLabel(kind, namespace, componentName, appName, mode, key string)
EnsurePodIsUp(namespace, podName string)
AssertNonAuthenticated()
}

View File

@@ -197,7 +197,11 @@ func CommonBeforeEach() CommonVar {
commonVar.OriginalKubeconfig = os.Getenv("KUBECONFIG")
if NeedsCluster(CurrentSpecReport().Labels()) {
LocalKubeconfigSet(commonVar.ConfigDir)
if IsAuth(CurrentSpecReport().Labels()) {
commonVar.Project = commonVar.CliRunner.CreateAndSetRandNamespaceProject()
} else {
commonVar.CliRunner.AssertNonAuthenticated()
}
} else {
// Disable the use of in-cluster configuration (seen in IBM Cloud pipeline)
os.Unsetenv("KUBERNETES_SERVICE_HOST")

View File

@@ -431,3 +431,7 @@ func (kubectl KubectlRunner) AssertNoContainsLabel(kind, namespace, componentNam
all := Cmd(kubectl.path, "get", kind, selector, "-n", namespace, "-o", "jsonpath={.items[0].metadata.labels}").ShouldPass().Out()
Expect(all).ToNot(ContainSubstring(fmt.Sprintf(`"%s"`, key)))
}
func (kubectl KubectlRunner) AssertNonAuthenticated() {
// Nothing to do
}

View File

@@ -622,3 +622,7 @@ func (oc OcRunner) EnsurePodIsUp(namespace, podName string) {
return strings.Contains(output, podName)
})
}
func (oc OcRunner) AssertNonAuthenticated() {
Cmd(oc.path, "whoami").ShouldFail()
}

View File

@@ -6,6 +6,7 @@ import (
const (
LabelNoCluster = "nocluster"
LabelUnauth = "unauth"
LabelPodman = "podman"
)
@@ -21,6 +22,15 @@ func NeedsCluster(labels []string) bool {
return true
}
func IsAuth(labels []string) bool {
for _, label := range labels {
if label == LabelUnauth {
return false
}
}
return true
}
func LabelPodmanIf(value bool, args ...interface{}) []interface{} {
res := []interface{}{}
if value {

View File

@@ -9,7 +9,12 @@ import (
"github.com/redhat-developer/odo/tests/helper"
)
var _ = Describe("odo analyze command tests", Label(helper.LabelNoCluster), func() {
var _ = Describe("odo analyze command tests", func() {
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
var _ = Context("label "+label, Label(label), func() {
var commonVar helper.CommonVar
// This is run before every Spec (It)
@@ -51,3 +56,7 @@ var _ = Describe("odo analyze command tests", Label(helper.LabelNoCluster), func
Expect(stderr).To(ContainSubstring("this command can be run with json output only"))
})
})
}
})

View File

@@ -28,7 +28,11 @@ var _ = Describe("odo describe component command tests", func() {
helper.CommonAfterEach(commonVar)
})
It("should fail, without cluster", Label(helper.LabelNoCluster), func() {
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
It("should fail, without cluster", Label(label), func() {
By("running odo describe component -o json with namespace flag without name flag", func() {
res := helper.Cmd("odo", "describe", "component", "--namespace", "default", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
@@ -60,6 +64,7 @@ var _ = Describe("odo describe component command tests", func() {
})
})
}
It("should fail, with cluster", func() {
By("running odo describe component -o json with an unknown name", func() {

View File

@@ -14,7 +14,12 @@ import (
"github.com/redhat-developer/odo/tests/helper"
)
var _ = Describe("odo devfile build-images command tests", Label(helper.LabelNoCluster), func() {
var _ = Describe("odo devfile build-images command tests", func() {
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
var _ = Context("label "+label, Label(label), func() {
var commonVar helper.CommonVar
@@ -260,5 +265,6 @@ CMD ["npm", "start"]
})
})
}
})
}
})

View File

@@ -22,7 +22,12 @@ import (
"github.com/redhat-developer/odo/tests/helper"
)
var _ = Describe("odo devfile init command tests", Label(helper.LabelNoCluster), func() {
var _ = Describe("odo devfile init command tests", func() {
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
var _ = Context("label "+label, Label(label), func() {
var commonVar helper.CommonVar
@@ -519,3 +524,5 @@ var _ = Describe("odo devfile init command tests", Label(helper.LabelNoCluster),
}
})
})
}
})

View File

@@ -104,6 +104,27 @@ var _ = Describe("odo list with devfile", func() {
helper.Chdir(commonVar.Context)
})
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
It("should list the local component when no authenticated", Label(label), func() {
By("checking the normal output", func() {
stdOut := helper.Cmd("odo", "list", "component").ShouldPass().Out()
Expect(stdOut).To(ContainSubstring(componentName))
})
By("checking the JSON output", func() {
res := helper.Cmd("odo", "list", "component", "-o", "json").ShouldPass()
stdout, stderr := res.Out(), res.Err()
Expect(helper.IsJSON(stdout)).To(BeTrue())
Expect(stderr).To(BeEmpty())
helper.JsonPathContentIs(stdout, "componentInDevfile", componentName)
helper.JsonPathContentIs(stdout, "components.0.name", componentName)
})
})
}
When("dev is running on cluster", func() {
BeforeEach(func() {
var err error
@@ -314,6 +335,11 @@ var _ = Describe("odo list with devfile", func() {
It("should show the language for 'Type' in odo list", Label(helper.LabelNoCluster), func() {
checkList(metadata.Language)
})
It("should show the language for 'Type' in odo list", Label(helper.LabelUnauth), func() {
checkList(metadata.Language)
})
When("the component is pushed in dev mode", func() {
var devSession helper.DevSession
BeforeEach(func() {
@@ -341,6 +367,9 @@ var _ = Describe("odo list with devfile", func() {
It("should show 'Not available' for 'Type' in odo list", Label(helper.LabelNoCluster), func() {
checkList("Not available")
})
It("should show 'Not available' for 'Type' in odo list", Label(helper.LabelUnauth), func() {
checkList("Not available")
})
When("the component is pushed", func() {
var devSession helper.DevSession
BeforeEach(func() {

View File

@@ -9,7 +9,13 @@ import (
"github.com/redhat-developer/odo/tests/helper"
)
var _ = Describe("odo devfile registry command tests", Label(helper.LabelNoCluster), func() {
var _ = Describe("odo devfile registry command tests", func() {
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
var _ = Context("label "+label, Label(label), func() {
const registryName string = "RegistryName"
// Use staging OCI-based registry for tests to avoid overload
@@ -143,5 +149,6 @@ var _ = Describe("odo devfile registry command tests", Label(helper.LabelNoClust
err := helper.Cmd("odo", "preference", "add", "registry", "RegistryFromGitHub", "https://github.com/devfile/registry").ShouldFail().Err()
helper.MatchAllInOutput(err, []string{"github", "no", "supported", "https://github.com/devfile/registry-support"})
})
})
}
})

View File

@@ -186,6 +186,10 @@ ComponentSettings:
Expect(out).To(ContainSubstring("Please ensure you have an active kubernetes context to your cluster."))
})
It("should fail, with unauth cluster", Label(helper.LabelUnauth), func() {
_ = helper.Cmd("odo", "list", commandName).ShouldFail()
})
It(fmt.Sprintf("should successfully list all the %ss", commandName), func() {
Eventually(func() string {
out := helper.Cmd("odo", "list", commandName).ShouldPass().Out()

View File

@@ -13,7 +13,14 @@ import (
const promptMessageSubString = "Help odo improve by allowing it to collect usage data."
var _ = Describe("odo preference and config command tests", Label(helper.LabelNoCluster), func() {
var _ = Describe("odo preference and config command tests", func() {
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
var _ = Context("label "+label, Label(label), func() {
// TODO: A neater way to provide odo path. Currently we assume odo and oc in $PATH already.
var commonVar helper.CommonVar
@@ -192,5 +199,6 @@ OdoSettings:
Expect(output).ToNot(ContainSubstring(promptMessageSubString))
})
})
})
}
})

View File

@@ -29,7 +29,11 @@ var _ = Describe("odo remove binding command tests", func() {
helper.Cmd("odo", "init", "--name", "mynode", "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-service-binding-files.yaml")).ShouldPass()
})
When("removing the binding", Label(helper.LabelNoCluster), func() {
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
When("removing the binding", Label(label), func() {
BeforeEach(func() {
helper.Cmd("odo", "remove", "binding", "--name", bindingName).ShouldPass()
})
@@ -38,9 +42,12 @@ var _ = Describe("odo remove binding command tests", func() {
Expect(components).To(BeNil())
})
})
It("should fail to remove binding that does not exist", Label(helper.LabelNoCluster), func() {
It("should fail to remove binding that does not exist", func() {
helper.Cmd("odo", "remove", "binding", "--name", "my-binding").ShouldFail()
})
}
When("odo dev is running", func() {
var session helper.DevSession
BeforeEach(func() {

View File

@@ -26,7 +26,12 @@ var _ = Describe("odo generic", func() {
helper.CommonAfterEach(commonVar)
})
When("running odo --help", Label(helper.LabelNoCluster), func() {
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
Context("label "+label, Label(label), func() {
When("running odo --help", func() {
var output string
BeforeEach(func() {
output = helper.Cmd("odo", "--help").ShouldPass().Out()
@@ -37,7 +42,7 @@ var _ = Describe("odo generic", func() {
})
When("running odo without subcommand and flags", Label(helper.LabelNoCluster), func() {
When("running odo without subcommand and flags", func() {
var output string
BeforeEach(func() {
output = helper.Cmd("odo").ShouldPass().Out()
@@ -47,12 +52,12 @@ var _ = Describe("odo generic", func() {
})
})
It("returns error when using an invalid command", Label(helper.LabelNoCluster), func() {
It("returns error when using an invalid command", func() {
output := helper.Cmd("odo", "hello").ShouldFail().Err()
Expect(output).To(ContainSubstring("Invalid command - see available commands/subcommands above"))
})
It("returns JSON error", Label(helper.LabelNoCluster), func() {
It("returns JSON error", func() {
By("using an invalid command with JSON output", func() {
res := helper.Cmd("odo", "unknown-command", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
@@ -82,10 +87,12 @@ var _ = Describe("odo generic", func() {
})
})
It("returns error when using an invalid command with --help", Label(helper.LabelNoCluster), func() {
It("returns error when using an invalid command with --help", func() {
output := helper.Cmd("odo", "hello", "--help").ShouldFail().Err()
Expect(output).To(ContainSubstring("unknown command 'hello', type --help for a list of all commands"))
})
})
}
Context("When deleting two project one after the other", func() {
It("should be able to delete sequentially", func() {
@@ -124,6 +131,10 @@ var _ = Describe("odo generic", func() {
reOdoVersion := `^odo\s*v[0-9]+.[0-9]+.[0-9]+(?:-\w+)?\s*\(\w+\)`
Expect(odoVersion).Should(MatchRegexp(reOdoVersion))
})
It("should show the version of odo major components", Label(helper.LabelUnauth), func() {
reOdoVersion := `^odo\s*v[0-9]+.[0-9]+.[0-9]+(?:-\w+)?\s*\(\w+\)`
Expect(odoVersion).Should(MatchRegexp(reOdoVersion))
})
})
Describe("Experimental Mode", func() {

View File

@@ -23,8 +23,12 @@ import (
"github.com/redhat-developer/odo/tests/helper"
)
var _ = Describe("odo init interactive command tests", Label(helper.LabelNoCluster), func() {
var _ = Describe("odo init interactive command tests", func() {
for _, label := range []string{
helper.LabelNoCluster, helper.LabelUnauth,
} {
label := label
var _ = Context("label "+label, Label(label), func() {
var commonVar helper.CommonVar
// This is run before every Spec (It)
@@ -518,3 +522,5 @@ var _ = Describe("odo init interactive command tests", Label(helper.LabelNoClust
})
})
})
}
})