Skip to content

Commit

Permalink
Refactored test, incorporated feedback, and added test to kubernetes …
Browse files Browse the repository at this point in the history
…and ocp tests
  • Loading branch information
rnapoles-rh committed Apr 7, 2022
1 parent 7c62587 commit 46387f7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 50 deletions.
1 change: 1 addition & 0 deletions .ibm/pipelines/kubernetes-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cleanup_namespaces
make test-interactive
make test-e2e-devfile
make test-cmd-project
make test-generic
) |& tee "/tmp/${LOGFILE}"
RESULT=${PIPESTATUS[0]}

Expand Down
1 change: 1 addition & 0 deletions .ibm/pipelines/openshift-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cleanup_namespaces
make test-cmd-login-logout
make test-cmd-project
make test-e2e-devfile
make test-generic
) |& tee "/tmp/${LOGFILE}"
RESULT=${PIPESTATUS[0]}

Expand Down
116 changes: 66 additions & 50 deletions tests/integration/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package integration

import (
"regexp"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -28,59 +27,79 @@ var _ = Describe("odo generic", func() {
helper.CommonAfterEach(commonVar)
})

Context("Check the help usage for odo", func() {

It("Makes sure that we have the long-description when running odo and we dont error", func() {
output := helper.Cmd("odo").ShouldPass().Out()
Expect(output).To(ContainSubstring("To see a full list of commands, run 'odo --help'"))
When("running odo --help", func() {
var output string
BeforeEach(func() {
output = helper.Cmd("odo", "--help").ShouldPass().Out()
})

It("Make sure we have the full description when performing odo --help", func() {
output := helper.Cmd("odo", "--help").ShouldPass().Out()
Expect(output).To(ContainSubstring("Use \"odo [command] --help\" for more information about a command."))
It("retuns full help contents including usage, examples, commands, utility commands, component shortcuts, and flags sections", func() {
output = helper.Cmd("odo", "--help").ShouldPass().Out()
helper.MatchAllInOutput(output, []string{"Usage:", "Examples:", "Main Commands:", "OpenShift Commands:", "Utility Commands:", "Flags:"})
})

It("Fail when entering an incorrect name for a component", func() {
output := helper.Cmd("odo", "delete", "foobar").ShouldFail().Err()
Expect(output).To(ContainSubstring("Subcommand not found, use one of the available commands"))
})
})

It("Fail with showing help only once for incorrect command", func() {
output := helper.Cmd("odo", "hello").ShouldFail().Err()
Expect(strings.Count(output, "odo [flags]")).Should(Equal(1))
When("running odo without subcommand and flags", func() {
var output string
BeforeEach(func() {
output = helper.Cmd("odo").ShouldPass().Out()
})
It("a short vesion of help contents is returned, an error is not expected", func() {
Expect(output).To(ContainSubstring("To see a full list of commands, run 'odo --help'"))
})
})

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("when using an invalid subcommand it fails if entering an incorrect name for a component", func() {
output := helper.Cmd("odo", "delete", "foobar").ShouldFail().Err()
Expect(output).To(ContainSubstring("Subcommand not found, use one of the available commands"))
})

// Disabling test temporarily while odo registry gets developed
// When("executing catalog list without component directory", func() {
// var stdOut string
// BeforeEach(func() {
// stdOut = helper.Cmd("odo", "catalog", "list", "components").ShouldPass().Out()
// })
// It("should list all devfile components", func() {
// // stdOut := helper.Cmd("odo", "catalog", "list", "components").ShouldPass().Out()
// helper.MatchAllInOutput(stdOut, []string{"Devfile", "nodejs", "python", "php", "go", "java"})
// })
// })

// Disabling test temporarily while odo registry gets developed
// When("searching the catalog for a non existing component", func() {
// var output string
// var componentRandomName string
// BeforeEach(func() {
// componentRandomName := helper.RandString(7)
// output = helper.Cmd("odo", "catalog", "search", "component", componentRandomName).ShouldFail().Err()
// })
// It("searches for the component and returs message indicating that no component matched the query", func() {
// Expect(output).To(ContainSubstring("no component matched the query: " + componentRandomName))
// })
// })

// Test machine readable output
Context("when creating project -o json", func() {
When("creating a project using -o json flag", func() {
var projectName string
JustBeforeEach(func() {
projectName = helper.RandString(6)
})
JustAfterEach(func() {
helper.DeleteProject(projectName)
})

// odo project create foobar -o json
It("should be able to create project and show output in json format", func() {
It("should create the project and show output in json format", func() {
actual := helper.Cmd("odo", "project", "create", projectName, "-o", "json").ShouldPass().Out()
values := gjson.GetMany(actual, "kind", "metadata.name", "status.active")
expected := []string{"Project", projectName, "true"}
Expect(helper.GjsonMatcher(values, expected)).To(Equal(true))
})
})

Context("Creating same project twice with flag -o json", func() {
var projectName string
JustBeforeEach(func() {
projectName = helper.RandString(6)
})
JustAfterEach(func() {
helper.DeleteProject(projectName)
})
// odo project create foobar -o json (x2)
It("should fail along with proper machine readable output", func() {
It("should fail if trying to create the project twice along with proper machine readable output", func() {
helper.Cmd("odo", "project", "create", projectName).ShouldPass()
actual := helper.Cmd("odo", "project", "create", projectName, "-o", "json").ShouldFail().Err()
valuesC := gjson.GetMany(actual, "kind", "message")
Expand All @@ -90,50 +109,47 @@ var _ = Describe("odo generic", func() {
})
})

Context("Delete the project with flag -o json", func() {
When("deleting a project with flag -o json", func() {
var projectName string
JustBeforeEach(func() {
projectName = helper.RandString(6)
})

// odo project delete foobar -o json
It("should be able to delete project and show output in json format", func() {
It("should delete the project and show output in json format", func() {
helper.Cmd("odo", "project", "create", projectName, "-o", "json").ShouldPass()

actual := helper.Cmd("odo", "project", "delete", projectName, "-o", "json").ShouldPass().Out()
valuesDel := gjson.GetMany(actual, "kind", "message")
expectedDel := []string{"Status", "Deleted project"}
Expect(helper.GjsonMatcher(valuesDel, expectedDel)).To(Equal(true))

})

})

Context("When deleting two project one after the other", func() {
It("should be able to delete sequentially", func() {
When("deleting two projects one after the other", func() {
It("should be able to delete them sequentially", func() {
project1 := helper.CreateRandProject()
project2 := helper.CreateRandProject()

helper.DeleteProject(project2)
helper.DeleteProject(project1)
helper.DeleteProject(project2)
})
})

Context("When deleting three project one after the other in opposite order", func() {
It("should be able to delete", func() {
It("should be able to delete them in any order", func() {
project1 := helper.CreateRandProject()
project2 := helper.CreateRandProject()
project3 := helper.CreateRandProject()

helper.DeleteProject(project1)
helper.DeleteProject(project2)
helper.DeleteProject(project1)
helper.DeleteProject(project3)

})
})

Context("when executing odo version command", func() {
When("executing odo version command", func() {
var odoVersion string
BeforeEach(func() {
odoVersion = helper.Cmd("odo", "version").ShouldPass().Out()
})

It("should show the version of odo major components including server login URL", func() {
odoVersion := helper.Cmd("odo", "version").ShouldPass().Out()
reOdoVersion := regexp.MustCompile(`^odo\s*v[0-9]+.[0-9]+.[0-9]+(?:-\w+)?\s*\(\w+\)`)
odoVersionStringMatch := reOdoVersion.MatchString(odoVersion)
rekubernetesVersion := regexp.MustCompile(`Kubernetes:\s*v[0-9]+.[0-9]+.[0-9]+((-\w+\.[0-9]+)?\+\w+)?`)
Expand Down

0 comments on commit 46387f7

Please sign in to comment.