Skip to content

Commit

Permalink
TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
kadel committed May 21, 2020
1 parent 8e09b0b commit b6850cb
Show file tree
Hide file tree
Showing 28 changed files with 1,141 additions and 1,560 deletions.
19 changes: 3 additions & 16 deletions docs/dev/development.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,14 @@ Context("when running help for storage command", func() {
----
For example:
var _ = Describe("odo generic", func() {
var project string
var context string
var oc helper.OcRunner
var globals helper.Globals
BeforeEach(func() {
oc = helper.NewOcRunner("oc")
SetDefaultEventuallyTimeout(10 * time.Minute)
context = helper.CreateNewContext()
globals = helperCommonBeforeEach()
})
AfterEach(func() {
os.RemoveAll(context)
os.CommonAfterEach(globals)
})
Context("deploying a component with a specific image name", func() {
JustBeforeEach(func() {
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
project = helper.CreateRandProject()
})
JustAfterEach(func() {
helper.DeleteProject(project)
os.Unsetenv("GLOBALODOCONFIG")
})
It("should deploy the component", func() {
helper.CmdShouldPass("git", "clone", "https://github.com/openshift/nodejs-ex", context+"/nodejs-ex")
helper.CmdShouldPass("odo", "create", "nodejs:latest", "testversioncmp", "--project", project, "--context", context+"/nodejs-ex")
Expand Down
65 changes: 21 additions & 44 deletions tests/e2escenarios/e2e_beta_test.go
Original file line number Diff line number Diff line change
@@ -1,63 +1,47 @@
package e2escenarios

import (
"os"
"path/filepath"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper"
)

var _ = Describe("odo core beta flow", func() {
//new clean project and context for each test
var project string
var context string

// current directory and project (before any test is run) so it can restored after all testing is done
var originalDir string

var oc helper.OcRunner
// path to odo binary
var odo string
var globals helper.Globals

BeforeEach(func() {
// Set default timeout for Eventually assertions
// commands like odo push, might take a long time
SetDefaultEventuallyTimeout(10 * time.Minute)
SetDefaultConsistentlyDuration(30 * time.Second)
globals = helper.CommonBeforeEach()

// initialize oc runner
// right now it uses oc binary, but we should convert it to client-go
oc = helper.NewOcRunner("oc")
odo = "odo"

context = helper.CreateNewContext()
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
project = helper.CreateRandProject()
})

AfterEach(func() {
helper.DeleteProject(project)
helper.DeleteDir(context)
os.Unsetenv("GLOBALODOCONFIG")
helper.CommonAfterEeach(globals)

})

// abstract main test to the function, to allow running the same test in a different context (slightly different arguments)
TestBasicCreateConfigPush := func(extraArgs ...string) {
createSession := helper.CmdShouldPass(odo, append([]string{"component", "create", "java:8", "mycomponent", "--app", "myapp", "--project", project}, extraArgs...)...)
createSession := helper.CmdShouldPass(odo, append([]string{"component", "create", "java:8", "mycomponent", "--app", "myapp", "--project", globals.Project}, extraArgs...)...)
// output of the commands should point user to running "odo push"
Expect(createSession).Should(ContainSubstring("odo push"))
configFile := filepath.Join(context, ".odo", "config.yaml")
configFile := filepath.Join(globals.Context, ".odo", "config.yaml")
Expect(configFile).To(BeARegularFile())
helper.FileShouldContainSubstring(configFile, "Name: mycomponent")
helper.FileShouldContainSubstring(configFile, "Type: java")
helper.FileShouldContainSubstring(configFile, "Application: myapp")
helper.FileShouldContainSubstring(configFile, "SourceType: local")
// SourcePath should be relative
//helper.FileShouldContainSubstring(configFile, "SourceLocation: .")
helper.FileShouldContainSubstring(configFile, "Project: "+project)
helper.FileShouldContainSubstring(configFile, "Project: "+globals.Project)

configSession := helper.CmdShouldPass(odo, append([]string{"config", "set", "--env", "FOO=bar"}, extraArgs...)...)
// output of the commands should point user to running "odo push"
Expand All @@ -74,7 +58,7 @@ var _ = Describe("odo core beta flow", func() {

helper.CmdShouldPass(odo, append([]string{"push"}, extraArgs...)...)

dcSession := oc.GetComponentDC("mycomponent", "myapp", project)
dcSession := oc.GetComponentDC("mycomponent", "myapp", globals.Project)
Expect(dcSession).Should(ContainSubstring("app.kubernetes.io/instance: mycomponent"))
Expect(dcSession).Should(ContainSubstring("app.kubernetes.io/component-source-type: local"))
Expect(dcSession).Should(ContainSubstring("app.kubernetes.io/name: java"))
Expand All @@ -84,56 +68,49 @@ var _ = Describe("odo core beta flow", func() {
Expect(dcSession).Should(ContainSubstring("name: FOO"))
Expect(dcSession).Should(ContainSubstring("value: bar"))

routeSession := oc.GetComponentRoutes("mycomponent", "myapp", project)
routeSession := oc.GetComponentRoutes("mycomponent", "myapp", globals.Project)
// check that route is pointing gto right port and component
Expect(routeSession).Should(ContainSubstring("targetPort: 8080"))
Expect(routeSession).Should(ContainSubstring("name: mycomponent-myapp"))
url := oc.GetFirstURL("mycomponent", "myapp", project)
url := oc.GetFirstURL("mycomponent", "myapp", globals.Project)
helper.HttpWaitFor("http://"+url, "Hello World from Javalin!", 10, 5)
}

Context("when component is in the current directory", func() {
// we will be testing components that are created from the current directory
// switch to the clean context dir before each test
JustBeforeEach(func() {
originalDir = helper.Getwd()
helper.Chdir(context)
})
// go back to original directory after each test
JustAfterEach(func() {
helper.Chdir(originalDir)
helper.Chdir(globals.Context)
})

It("'odo component' should fail if there already is .odo dir", func() {
helper.CmdShouldPass("odo", "component", "create", "nodejs", "--project", project)
helper.CmdShouldFail("odo", "component", "create", "nodejs", "--project", project)
helper.CmdShouldPass("odo", "component", "create", "nodejs", "--project", globals.Project)
helper.CmdShouldFail("odo", "component", "create", "nodejs", "--project", globals.Project)
})

It("'odo config' should fail if there is no .odo dir", func() {
helper.CmdShouldFail("odo", "config", "set", "memory", "2Gi")
})

It("create local java component and push code", func() {
oc.ImportJavaIS(project)
helper.CopyExample(filepath.Join("source", "openjdk"), context)
oc.ImportJavaIS(globals.Project)
helper.CopyExample(filepath.Join("source", "openjdk"), globals.Context)
TestBasicCreateConfigPush()
})
})

Context("when --context flag is used", func() {
It("odo component should fail if there already is .odo dir", func() {
helper.CmdShouldPass("odo", "component", "create", "nodejs", "--context", context, "--project", project)
helper.CmdShouldFail("odo", "component", "create", "nodejs", "--context", context, "--project", project)
helper.CmdShouldPass("odo", "component", "create", "nodejs", "--context", globals.Context, "--project", globals.Project)
helper.CmdShouldFail("odo", "component", "create", "nodejs", "--context", globals.Context, "--project", globals.Project)
})

It("odo config should fail if there is no .odo dir", func() {
helper.CmdShouldFail("odo", "config", "set", "memory", "2Gi", "--context", context)
helper.CmdShouldFail("odo", "config", "set", "memory", "2Gi", "--context", globals.Context)
})

It("create local java component and push code", func() {
oc.ImportJavaIS(project)
helper.CopyExample(filepath.Join("source", "openjdk"), context)
TestBasicCreateConfigPush("--context", context)
oc.ImportJavaIS(globals.Project)
helper.CopyExample(filepath.Join("source", "openjdk"), globals.Context)
TestBasicCreateConfigPush("--context", globals.Context)
})
})
})
46 changes: 20 additions & 26 deletions tests/e2escenarios/e2e_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@ import (
)

var _ = Describe("odo supported images e2e tests", func() {
//new clean project and context for each test
var project string
var context string

appName := "app"

var oc helper.OcRunner
var globals helper.Globals

BeforeEach(func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
oc = helper.NewOcRunner("oc")
context = helper.CreateNewContext()
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
project = helper.CreateRandProject()
globals = helper.CommonBeforeEach()
})

AfterEach(func() {
helper.DeleteProject(project)
helper.DeleteDir(context)
os.Unsetenv("GLOBALODOCONFIG")
helper.CommonAfterEeach(globals)
})

OdoWatch := func(srcType, routeURL, project, appName, context string) {
Expand Down Expand Up @@ -136,43 +130,43 @@ var _ = Describe("odo supported images e2e tests", func() {

Context("odo supported images deployment", func() {
It("Should be able to verify the openjdk18-openshift image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("redhat-openjdk-18", "openjdk18-openshift:latest"), "java:8", project)
verifySupportedImage(filepath.Join("redhat-openjdk-18", "openjdk18-openshift:latest"), "openjdk", "java:8", project, appName, context)
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("redhat-openjdk-18", "openjdk18-openshift:latest"), "java:8", globals.Project)
verifySupportedImage(filepath.Join("redhat-openjdk-18", "openjdk18-openshift:latest"), "openjdk", "java:8", globals.Project, appName, globals.Context)
})

It("Should be able to verify the openjdk-11-rhel7 image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("openjdk", "openjdk-11-rhel7:latest"), "java:8", project)
verifySupportedImage(filepath.Join("openjdk", "openjdk-11-rhel7:latest"), "openjdk", "java:8", project, appName, context)
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("openjdk", "openjdk-11-rhel7:latest"), "java:8", globals.Project)
verifySupportedImage(filepath.Join("openjdk", "openjdk-11-rhel7:latest"), "openjdk", "java:8", globals.Project, appName, globals.Context)
})

It("Should be able to verify the nodejs-8-rhel7 image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("rhscl", "nodejs-8-rhel7:latest"), "nodejs:latest", project)
verifySupportedImage(filepath.Join("rhscl", "nodejs-8-rhel7:latest"), "nodejs", "nodejs:latest", project, appName, context)
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("rhscl", "nodejs-8-rhel7:latest"), "nodejs:latest", globals.Project)
verifySupportedImage(filepath.Join("rhscl", "nodejs-8-rhel7:latest"), "nodejs", "nodejs:latest", globals.Project, appName, globals.Context)
})

It("Should be able to verify the nodejs-8 image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("rhoar-nodejs", "nodejs-8:latest"), "nodejs:latest", project)
verifySupportedImage(filepath.Join("rhoar-nodejs", "nodejs-8:latest"), "nodejs", "nodejs:latest", project, appName, context)
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("rhoar-nodejs", "nodejs-8:latest"), "nodejs:latest", globals.Project)
verifySupportedImage(filepath.Join("rhoar-nodejs", "nodejs-8:latest"), "nodejs", "nodejs:latest", globals.Project, appName, globals.Context)
})

It("Should be able to verify the nodejs-10 image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("rhoar-nodejs", "nodejs-10:latest"), "nodejs:latest", project)
verifySupportedImage(filepath.Join("rhoar-nodejs", "nodejs-10:latest"), "nodejs", "nodejs:latest", project, appName, context)
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("rhoar-nodejs", "nodejs-10:latest"), "nodejs:latest", globals.Project)
verifySupportedImage(filepath.Join("rhoar-nodejs", "nodejs-10:latest"), "nodejs", "nodejs:latest", globals.Project, appName, globals.Context)
})

It("Should be able to verify the centos7-s2i-nodejs image", func() {
oc.ImportImageFromRegistry("docker.io", filepath.Join("bucharestgold", "centos7-s2i-nodejs"), "nodejs:latest", project)
verifySupportedImage(filepath.Join("bucharestgold", "centos7-s2i-nodejs"), "nodejs", "nodejs:latest", project, appName, context)
oc.ImportImageFromRegistry("docker.io", filepath.Join("bucharestgold", "centos7-s2i-nodejs"), "nodejs:latest", globals.Project)
verifySupportedImage(filepath.Join("bucharestgold", "centos7-s2i-nodejs"), "nodejs", "nodejs:latest", globals.Project, appName, globals.Context)
})

It("Should be able to verify the centos7-s2i-nodejs:10.x image", func() {
oc.ImportImageFromRegistry("docker.io", filepath.Join("bucharestgold", "centos7-s2i-nodejs:10.x"), "nodejs:latest", project)
verifySupportedImage(filepath.Join("bucharestgold", "centos7-s2i-nodejs:10.x"), "nodejs", "nodejs:latest", project, appName, context)
oc.ImportImageFromRegistry("docker.io", filepath.Join("bucharestgold", "centos7-s2i-nodejs:10.x"), "nodejs:latest", globals.Project)
verifySupportedImage(filepath.Join("bucharestgold", "centos7-s2i-nodejs:10.x"), "nodejs", "nodejs:latest", globals.Project, appName, globals.Context)
})

It("Should be able to verify the nodejs-8-centos7 image", func() {
oc.ImportImageFromRegistry("docker.io", filepath.Join("centos", "nodejs-8-centos7:latest"), "nodejs:latest", project)
verifySupportedImage(filepath.Join("centos", "nodejs-8-centos7:latest"), "nodejs", "nodejs:latest", project, appName, context)
oc.ImportImageFromRegistry("docker.io", filepath.Join("centos", "nodejs-8-centos7:latest"), "nodejs:latest", globals.Project)
verifySupportedImage(filepath.Join("centos", "nodejs-8-centos7:latest"), "nodejs", "nodejs:latest", globals.Project, appName, globals.Context)
})
})
})
Loading

0 comments on commit b6850cb

Please sign in to comment.