Skip to content

Commit

Permalink
Run link command test in parallel (#1827)
Browse files Browse the repository at this point in the history
* Run link command test in parallel

* Updated oc helper test file

* Updated Makefile

* Updated doc

* Updated test file
  • Loading branch information
amitkrout authored and openshift-merge-robot committed Jul 1, 2019
1 parent f4b3cbf commit 842a4e5
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ test-service-e2e:
# Run link e2e tests
.PHONY: test-link-e2e
test-link-e2e:
go test -v github.com/openshift/odo/tests/integration --ginkgo.focus="odoLinkE2e" -ginkgo.slowSpecThreshold=$(SLOW_SPEC_THRESHOLD) -ginkgo.v -timeout $(TIMEOUT)
ginkgo -v -nodes=$(TEST_EXEC_NODES) -focus="odoLinkE2e" slowSpecThreshold=$(SLOW_SPEC_THRESHOLD) -randomizeAllSpecs tests/integration/ -timeout $(TIMEOUT)

# Run watch e2e tests
.PHONY: test-watch-e2e
Expand Down
14 changes: 14 additions & 0 deletions docs/development.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ $ make test-service-e2e
----
+

Run link/unlink command integration test
+
----
$ make test-link-e2e
----
+

* To run the test sequentially or on single ginkgo test node use enviornment variable `TEST_EXEC_NODES`:
+
Run component command integration test
Expand Down Expand Up @@ -268,6 +275,13 @@ $ make test-service-e2e TEST_EXEC_NODES=1
----
+

Run link/unlink command integration test
+
----
$ make test-link-e2e TEST_EXEC_NODES=1
----
+

* For the entire integration test suite use:
+
----
Expand Down
4 changes: 2 additions & 2 deletions tests/helper/helper_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ func (oc *OcRunner) GetVolumeMountPath(dcName string, namespace string) string {
}

// GetEnvFromEntry returns envFrom entry
func (oc *OcRunner) GetEnvFromEntry(componentName string, appName string) string {
envFromOut := CmdShouldPass(oc.path, "get", "dc", componentName+"-"+appName,
func (oc *OcRunner) GetEnvFromEntry(componentName string, appName string, projectName string) string {
envFromOut := CmdShouldPass(oc.path, "get", "dc", componentName+"-"+appName, "--namespace", projectName,
"-o", "jsonpath='{.spec.template.spec.containers[0].envFrom}'")
return strings.TrimSpace(envFromOut)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("odoLinkE2e", func() {

//new clean project and context for each test
var project string
var context1, context2, context3, context4 string
var context, context1, context2 string
var originalDir string

// Setup up state for each test spec
Expand All @@ -26,16 +26,33 @@ var _ = Describe("odoLinkE2e", func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
oc = helper.NewOcRunner("oc")
project = helper.CreateRandProject()
context = helper.CreateNewContext()
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
})

// Clean up after the test
// This is run after every Spec (It)
var _ = AfterEach(func() {
helper.DeleteProject(project)
os.RemoveAll(".odo")
helper.DeleteDir(context)
os.Unsetenv("GLOBALODOCONFIG")
})

Context("odo link/unlink handling between components", func() {
Context("when running help for link command", func() {
It("should display the help", func() {
appHelp := helper.CmdShouldPass("odo", "link", "-h")
Expect(appHelp).To(ContainSubstring("Link component to a service or component"))
})
})

Context("when running help for unlink command", func() {
It("should display the help", func() {
appHelp := helper.CmdShouldPass("odo", "unlink", "-h")
Expect(appHelp).To(ContainSubstring("Unlink component or service from a component"))
})
})

Context("When link between components using wrong port", func() {
JustBeforeEach(func() {
context1 = helper.CreateNewContext()
context2 = helper.CreateNewContext()
Expand All @@ -44,77 +61,100 @@ var _ = Describe("odoLinkE2e", func() {
helper.DeleteDir(context1)
helper.DeleteDir(context2)
})
It("reports error when using wrong port", func() {
It("should fail", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context1)
helper.CmdShouldPass("odo", "create", "nodejs", "frontend", "--context", context1)
helper.CmdShouldPass("odo", "create", "nodejs", "frontend", "--context", context1, "--project", project)
helper.CmdShouldPass("odo", "push", "--context", context1)
helper.CopyExample(filepath.Join("source", "python"), context2)
helper.CmdShouldPass("odo", "create", "python", "backend", "--context", context2)
helper.CmdShouldPass("odo", "create", "python", "backend", "--context", context2, "--project", project)
helper.CmdShouldPass("odo", "push", "--context", context2)
stdErr := helper.CmdShouldFail("odo", "link", "backend", "--component", "frontend", "--context", context2, "--port", "1234")
stdErr := helper.CmdShouldFail("odo", "link", "backend", "--component", "frontend", "--project", project, "--context", context2, "--port", "1234")
Expect(stdErr).To(ContainSubstring("Unable to properly link to component backend using port 1234"))
})
It("link the frontend application to the backend", func() {
})

Context("When handiling link/unlink between components", func() {
JustBeforeEach(func() {
context1 = helper.CreateNewContext()
context2 = helper.CreateNewContext()
})
JustAfterEach(func() {
helper.DeleteDir(context1)
helper.DeleteDir(context2)
})
It("should link the frontend application to the backend and then unlink successfully", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context1)
helper.CmdShouldPass("odo", "create", "nodejs", "frontend", "--context", context1)
helper.CmdShouldPass("odo", "create", "nodejs", "frontend", "--context", context1, "--project", project)
helper.CmdShouldPass("odo", "push", "--context", context1)
helper.CopyExample(filepath.Join("source", "python"), context2)
helper.CmdShouldPass("odo", "create", "python", "backend", "--context", context2)
helper.CmdShouldPass("odo", "create", "python", "backend", "--context", context2, "--project", project)
helper.CmdShouldPass("odo", "push", "--context", context2)
helper.CmdShouldPass("odo", "link", "backend", "--component", "frontend", "--context", context2)
helper.CmdShouldPass("odo", "link", "backend", "--component", "frontend", "--project", project, "--context", context2)
// ensure that the proper envFrom entry was created
envFromOutput := oc.GetEnvFromEntry("frontend", "app")
envFromOutput := oc.GetEnvFromEntry("frontend", "app", project)
Expect(envFromOutput).To(ContainSubstring("backend"))
outputErr := helper.CmdShouldFail("odo", "link", "backend", "--component", "frontend", "--context", context2)
outputErr := helper.CmdShouldFail("odo", "link", "backend", "--component", "frontend", "--project", project, "--context", context2)
Expect(outputErr).To(ContainSubstring("been linked"))
helper.CmdShouldPass("odo", "unlink", "backend", "--component", "frontend", "--context", context2)
helper.CmdShouldPass("odo", "unlink", "backend", "--component", "frontend", "--project", project, "--context", context2)
})
})

Context("odo link/unlink handling between components and service", func() {
Context("When link backend between component and service", func() {
JustBeforeEach(func() {
context3 = helper.CreateNewContext()
context4 = helper.CreateNewContext()
context1 = helper.CreateNewContext()
context2 = helper.CreateNewContext()
originalDir = helper.Getwd()
})
JustAfterEach(func() {
helper.Chdir(originalDir)
helper.DeleteDir(context3)
helper.DeleteDir(context4)
helper.DeleteDir(context1)
helper.DeleteDir(context2)
})
It("should link backend to service", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context3)
helper.CmdShouldPass("odo", "create", "nodejs", "frontend", "--context", context3)
helper.CmdShouldPass("odo", "push", "--context", context3)
helper.CopyExample(filepath.Join("source", "python"), context4)
helper.CmdShouldPass("odo", "create", "python", "backend", "--context", context4)
helper.CmdShouldPass("odo", "push", "--context", context4)
helper.CmdShouldPass("odo", "link", "backend", "--component", "frontend", "--context", context4)
helper.Chdir(context4)
It("should link backend to service successfully", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context1)
helper.CmdShouldPass("odo", "create", "nodejs", "frontend", "--context", context1, "--project", project)
helper.CmdShouldPass("odo", "push", "--context", context1)
helper.CopyExample(filepath.Join("source", "python"), context2)
helper.CmdShouldPass("odo", "create", "python", "backend", "--context", context2, "--project", project)
helper.CmdShouldPass("odo", "push", "--context", context2)
helper.CmdShouldPass("odo", "link", "backend", "--component", "frontend", "--project", project, "--context", context2)
// Switching to context2 dir because --context flag is not supported with service command
helper.Chdir(context2)
helper.CmdShouldPass("odo", "service", "create", "mysql-persistent")

ocArgs := []string{"get", "serviceinstance", "-o", "name"}
helper.WaitForCmdOut("oc", ocArgs, 1, true, func(output string) bool {
return strings.Contains(output, "mysql-persistent")
})
helper.CmdShouldPass("odo", "link", "mysql-persistent", "--wait-for-target", "--component", "backend")
helper.CmdShouldPass("odo", "link", "mysql-persistent", "--wait-for-target", "--component", "backend", "--project", project)
// ensure that the proper envFrom entry was created
envFromOutput := oc.GetEnvFromEntry("backend", "app")
envFromOutput := oc.GetEnvFromEntry("backend", "app", project)
Expect(envFromOutput).To(ContainSubstring("mysql-persistent"))

outputErr := helper.CmdShouldFail("odo", "link", "mysql-persistent", "--component", "backend", "--context", context4)
outputErr := helper.CmdShouldFail("odo", "link", "mysql-persistent", "--component", "backend", "--project", project, "--context", context2)
Expect(outputErr).To(ContainSubstring("been linked"))
})
})

It("Delete service and unlink the backend from the frontend", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context3)
helper.CmdShouldPass("odo", "create", "nodejs", "frontend", "--context", context3)
helper.CmdShouldPass("odo", "push", "--context", context3)
helper.CopyExample(filepath.Join("source", "python"), context4)
helper.CmdShouldPass("odo", "create", "python", "backend", "--context", context4)
helper.CmdShouldPass("odo", "push", "--context", context4)
helper.CmdShouldPass("odo", "link", "backend", "--component", "frontend", "--context", context4)
helper.Chdir(context4)
Context("When deleting service and unlink the backend from the frontend", func() {
JustBeforeEach(func() {
context1 = helper.CreateNewContext()
context2 = helper.CreateNewContext()
originalDir = helper.Getwd()
})
JustAfterEach(func() {
helper.Chdir(originalDir)
helper.DeleteDir(context1)
helper.DeleteDir(context2)
})
It("should pass", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context1)
helper.CmdShouldPass("odo", "create", "nodejs", "frontend", "--context", context1, "--project", project)
helper.CmdShouldPass("odo", "push", "--context", context1)
helper.CopyExample(filepath.Join("source", "python"), context2)
helper.CmdShouldPass("odo", "create", "python", "backend", "--context", context2, "--project", project)
helper.CmdShouldPass("odo", "push", "--context", context2)
helper.CmdShouldPass("odo", "link", "backend", "--component", "frontend", "--project", project, "--context", context2)
helper.Chdir(context2)
helper.CmdShouldPass("odo", "service", "create", "mysql-persistent")

ocArgs := []string{"get", "serviceinstance", "-o", "name"}
Expand All @@ -123,14 +163,14 @@ var _ = Describe("odoLinkE2e", func() {
})
helper.CmdShouldPass("odo", "service", "delete", "mysql-persistent", "-f")
// ensure that the backend no longer has an envFrom value
backendEnvFromOutput := oc.GetEnvFromEntry("backend", "app")
backendEnvFromOutput := oc.GetEnvFromEntry("backend", "app", project)
Expect(backendEnvFromOutput).To(Equal("''"))
// ensure that the frontend envFrom was not changed
frontEndEnvFromOutput := oc.GetEnvFromEntry("frontend", "app")
frontEndEnvFromOutput := oc.GetEnvFromEntry("frontend", "app", project)
Expect(frontEndEnvFromOutput).To(ContainSubstring("backend"))
helper.CmdShouldPass("odo", "unlink", "backend", "--component", "frontend")
helper.CmdShouldPass("odo", "unlink", "backend", "--component", "frontend", "--project", project)
// ensure that the proper envFrom entry was created
envFromOutput := oc.GetEnvFromEntry("frontend", "app")
envFromOutput := oc.GetEnvFromEntry("frontend", "app", project)
Expect(envFromOutput).To(Equal("''"))
})
})
Expand Down

0 comments on commit 842a4e5

Please sign in to comment.