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

Test with OpenShift cluster non authenticated #6395

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
21 changes: 21 additions & 0 deletions .ibm/pipelines/openshift-unauth-tests.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the other scripts, do we want to also export the DEVFILE_PROXY env var here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proxy running in the cluster, it is not accessible, I had to remove it or it contains an error message

make test-integration-openshift-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-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:
Expand Down
1 change: 1 addition & 0 deletions tests/helper/helper_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
6 changes: 5 additions & 1 deletion tests/helper/helper_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ func CommonBeforeEach() CommonVar {
commonVar.OriginalKubeconfig = os.Getenv("KUBECONFIG")
if NeedsCluster(CurrentSpecReport().Labels()) {
LocalKubeconfigSet(commonVar.ConfigDir)
commonVar.Project = commonVar.CliRunner.CreateAndSetRandNamespaceProject()
if IsAuth(CurrentSpecReport().Labels()) {
rm3l marked this conversation as resolved.
Show resolved Hide resolved
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")
Expand Down
4 changes: 4 additions & 0 deletions tests/helper/helper_kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions tests/helper/helper_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,7 @@ func (oc OcRunner) EnsurePodIsUp(namespace, podName string) {
return strings.Contains(output, podName)
})
}

func (oc OcRunner) AssertNonAuthenticated() {
Cmd(oc.path, "whoami").ShouldFail()
}
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
87 changes: 48 additions & 39 deletions tests/integration/cmd_analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,54 @@ import (
"github.com/redhat-developer/odo/tests/helper"
)

var _ = Describe("odo analyze command tests", Label(helper.LabelNoCluster), func() {
var commonVar helper.CommonVar

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
helper.Chdir(commonVar.Context)
})

// This is run after every Spec (It)
var _ = AfterEach(func() {
helper.CommonAfterEach(commonVar)
})

When("source files are in the directory", func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
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)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
helper.Chdir(commonVar.Context)
})

// This is run after every Spec (It)
var _ = AfterEach(func() {
helper.CommonAfterEach(commonVar)
})

When("source files are in the directory", func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
})

It("analyze should return correct value", func() {
res := helper.Cmd("odo", "analyze", "-o", "json").ShouldPass()
stdout, stderr := res.Out(), res.Err()
Expect(stderr).To(BeEmpty())
Expect(helper.IsJSON(stdout)).To(BeTrue())
helper.JsonPathContentIs(stdout, "0.devfile", "nodejs")
helper.JsonPathContentIs(stdout, "0.devfileRegistry", "DefaultDevfileRegistry")
})
})

It("analyze should fail in an empty directory", func() {
res := helper.Cmd("odo", "analyze", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
Expect(helper.IsJSON(stderr)).To(BeTrue())
helper.JsonPathContentContain(stderr, "message", "No valid devfile found for project in")
})

It("analyze should fail without json output", func() {
stderr := helper.Cmd("odo", "analyze").ShouldFail().Err()
Expect(stderr).To(ContainSubstring("this command can be run with json output only"))
})
})

It("analyze should return correct value", func() {
res := helper.Cmd("odo", "analyze", "-o", "json").ShouldPass()
stdout, stderr := res.Out(), res.Err()
Expect(stderr).To(BeEmpty())
Expect(helper.IsJSON(stdout)).To(BeTrue())
helper.JsonPathContentIs(stdout, "0.devfile", "nodejs")
helper.JsonPathContentIs(stdout, "0.devfileRegistry", "DefaultDevfileRegistry")
})
})

It("analyze should fail in an empty directory", func() {
res := helper.Cmd("odo", "analyze", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
Expect(helper.IsJSON(stderr)).To(BeTrue())
helper.JsonPathContentContain(stderr, "message", "No valid devfile found for project in")
})

It("analyze should fail without json output", func() {
stderr := helper.Cmd("odo", "analyze").ShouldFail().Err()
Expect(stderr).To(ContainSubstring("this command can be run with json output only"))
})
}

})
61 changes: 33 additions & 28 deletions tests/integration/cmd_describe_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,43 @@ var _ = Describe("odo describe component command tests", func() {
helper.CommonAfterEach(commonVar)
})

It("should fail, without cluster", Label(helper.LabelNoCluster), 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()
Expect(helper.IsJSON(stderr)).To(BeTrue())
Expect(stdout).To(BeEmpty())
helper.JsonPathContentContain(stderr, "message", "--namespace can be used only with --name")
})
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()
Expect(helper.IsJSON(stderr)).To(BeTrue())
Expect(stdout).To(BeEmpty())
helper.JsonPathContentContain(stderr, "message", "--namespace can be used only with --name")
})

By("running odo describe component -o json without name and without devfile in the current directory", func() {
res := helper.Cmd("odo", "describe", "component", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(helper.IsJSON(stderr)).To(BeTrue())
Expect(stdout).To(BeEmpty())
helper.JsonPathContentContain(stderr, "message", "The current directory does not represent an odo component")
})
By("running odo describe component -o json without name and without devfile in the current directory", func() {
res := helper.Cmd("odo", "describe", "component", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(helper.IsJSON(stderr)).To(BeTrue())
Expect(stdout).To(BeEmpty())
helper.JsonPathContentContain(stderr, "message", "The current directory does not represent an odo component")
})

By("running odo describe component with namespace flag without name flag", func() {
res := helper.Cmd("odo", "describe", "component", "--namespace", "default").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
Expect(stderr).To(ContainSubstring("--namespace can be used only with --name"))
})
By("running odo describe component with namespace flag without name flag", func() {
res := helper.Cmd("odo", "describe", "component", "--namespace", "default").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
Expect(stderr).To(ContainSubstring("--namespace can be used only with --name"))
})

By("running odo describe component without name and without devfile in the current directory", func() {
res := helper.Cmd("odo", "describe", "component").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
Expect(stderr).To(ContainSubstring("The current directory does not represent an odo component"))
})
By("running odo describe component without name and without devfile in the current directory", func() {
res := helper.Cmd("odo", "describe", "component").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
Expect(stderr).To(ContainSubstring("The current directory does not represent an odo component"))
})

})
})
}

It("should fail, with cluster", func() {
By("running odo describe component -o json with an unknown name", func() {
Expand Down
Loading