Skip to content

Commit

Permalink
Merge ae44703 into ac19ece
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy authored Dec 8, 2022
2 parents ac19ece + ae44703 commit 02902c4
Show file tree
Hide file tree
Showing 15 changed files with 1,576 additions and 1,440 deletions.
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
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
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

0 comments on commit 02902c4

Please sign in to comment.