Skip to content

Commit

Permalink
Test with OpenShift cluster non authenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Dec 8, 2022
1 parent a399313 commit 08f76d1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .ibm/pipelines/openshift-unauth-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/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}"

cleanup_namespaces

(
set -e
make install
make test-integration-cluster-unauth
) |& tee "/tmp/${LOGFILE}"

RESULT=${PIPESTATUS[0]}

save_logs "${LOGFILE}" "OpenShift Unauthenticated Tests" ${RESULT}

exit ${RESULT}
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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-cluster-unauth
test-integration-cluster-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:
Expand Down
4 changes: 3 additions & 1 deletion tests/helper/helper_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ func CommonBeforeEach() CommonVar {
commonVar.OriginalKubeconfig = os.Getenv("KUBECONFIG")
if NeedsCluster(CurrentSpecReport().Labels()) {
LocalKubeconfigSet(commonVar.ConfigDir)
commonVar.Project = commonVar.CliRunner.CreateAndSetRandNamespaceProject()
if IsAuth(CurrentSpecReport().Labels()) {
commonVar.Project = commonVar.CliRunner.CreateAndSetRandNamespaceProject()
}
} else {
// Disable the use of in-cluster configuration (seen in IBM Cloud pipeline)
os.Unsetenv("KUBERNETES_SERVICE_HOST")
Expand Down
10 changes: 10 additions & 0 deletions tests/helper/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

const (
LabelNoCluster = "nocluster"
LabelUnauth = "unauth"
LabelPodman = "podman"
)

Expand All @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/cmd_devfile_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ var _ = Describe("odo list with devfile", func() {
helper.Chdir(commonVar.Context)
})

It("should list the local component when no authenticated", Label(helper.LabelUnauth), 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
Expand Down

0 comments on commit 08f76d1

Please sign in to comment.