mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
Create DevSession for integration tests (#5569)
* Create DevSession for integration tests * Review * More doc * Update tests/integration/devfile/cmd_devfile_list_test.go Co-authored-by: Dharmit Shah <shahdharmit@gmail.com> Co-authored-by: Dharmit Shah <shahdharmit@gmail.com>
This commit is contained in:
114
tests/helper/helper_dev.go
Normal file
114
tests/helper/helper_dev.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"github.com/onsi/gomega/gexec"
|
||||
)
|
||||
|
||||
// DevSession represents a session running `odo dev`
|
||||
/*
|
||||
It can be used in different ways:
|
||||
|
||||
# Starting a session for a series of tests and stopping the session after the tests:
|
||||
|
||||
This format can be used when you want to run several independent tests
|
||||
when the `odo dev` command is running in the background
|
||||
|
||||
```
|
||||
When("running dev session", func() {
|
||||
var devSession DevSession
|
||||
BeforeEach(func() {
|
||||
devSession = helper.StartDevMode()
|
||||
})
|
||||
AfterEach(func() {
|
||||
devSession.Stop()
|
||||
})
|
||||
|
||||
It("...", func() {
|
||||
// Test with `dev odo` running in the background
|
||||
})
|
||||
It("...", func() {
|
||||
// Test with `dev odo` running in the background
|
||||
})
|
||||
})
|
||||
|
||||
# Starting a session and stopping it cleanly
|
||||
|
||||
This format can be used to test the behaviour of `odo dev` when it is stopped cleanly
|
||||
|
||||
When("running dev session and stopping it with cleanup", func() {
|
||||
BeforeEach(func() {
|
||||
devSession := helper.StartDevMode()
|
||||
defer devSession.Stop()
|
||||
[...]
|
||||
})
|
||||
|
||||
It("...", func() {
|
||||
// Test after `odo dev` has been stopped cleanly
|
||||
})
|
||||
It("...", func() {
|
||||
// Test after `odo dev` has been stopped cleanly
|
||||
})
|
||||
})
|
||||
|
||||
# Starting a session and stopping it immediately without cleanup
|
||||
|
||||
This format can be used to test the behaviour of `odo dev` when it is stopped with a KILL signal
|
||||
|
||||
When("running dev session and stopping it without cleanup", func() {
|
||||
BeforeEach(func() {
|
||||
devSession := helper.StartDevMode()
|
||||
defer devSession.Kill()
|
||||
[...]
|
||||
})
|
||||
|
||||
It("...", func() {
|
||||
// Test after `odo dev` has been killed
|
||||
})
|
||||
It("...", func() {
|
||||
// Test after `odo dev` has been killed
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
# Running a dev session and executing some tests inside this session
|
||||
|
||||
This format can be used to run a series of related tests in dev mode
|
||||
All tests will be ran in the same session (ideal for e2e tests)
|
||||
To run independent tests, previous formats should be used instead.
|
||||
|
||||
It("should do ... in dev mode", func() {
|
||||
helper.RunDevMode(func(session *gexec.Session) {
|
||||
// test on dev mode
|
||||
})
|
||||
})
|
||||
*/
|
||||
type DevSession struct {
|
||||
session *gexec.Session
|
||||
}
|
||||
|
||||
// StartDevMode starts a dev session with `odo dev`
|
||||
func StartDevMode() DevSession {
|
||||
session := CmdRunner("odo", "dev")
|
||||
WaitForOutputToContain("Waiting for something to change", 180, 10, session)
|
||||
return DevSession{
|
||||
session: session,
|
||||
}
|
||||
}
|
||||
|
||||
// Kill a Dev session abruptly, without handling any cleanup
|
||||
func (o DevSession) Kill() {
|
||||
o.session.Kill()
|
||||
}
|
||||
|
||||
// Stop a Dev session cleanly (equivalent as hitting Ctrl-c)
|
||||
func (o DevSession) Stop() {
|
||||
o.session.Interrupt()
|
||||
}
|
||||
|
||||
// RunDevMode runs a dev session and executes the `inside` code
|
||||
func RunDevMode(inside func(session *gexec.Session)) {
|
||||
session := StartDevMode()
|
||||
defer session.Stop()
|
||||
WaitForOutputToContain("Waiting for something to change", 180, 10, session.session)
|
||||
inside(session.session)
|
||||
}
|
||||
@@ -65,12 +65,11 @@ ComponentSettings:
|
||||
Expect(stdOut).To(ContainSubstring("No resource found for component %q in namespace %q", cmpName, commonVar.Project))
|
||||
})
|
||||
})
|
||||
When("the component is deployed in DEV mode", func() {
|
||||
When("the component is deployed in DEV mode and dev mode stopped", func() {
|
||||
var devSession helper.DevSession
|
||||
BeforeEach(func() {
|
||||
session := helper.CmdRunner("odo", "dev")
|
||||
defer session.Kill()
|
||||
helper.WaitForOutputToContain("Press Ctrl+c to exit", 180, 10, session)
|
||||
|
||||
devSession = helper.StartDevMode()
|
||||
defer devSession.Kill()
|
||||
Expect(commonVar.CliRunner.Run(getDeployArgs...).Out.Contents()).To(ContainSubstring(cmpName))
|
||||
})
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/gomega/gexec"
|
||||
|
||||
"github.com/redhat-developer/odo/pkg/util"
|
||||
"github.com/redhat-developer/odo/pkg/watch"
|
||||
"github.com/redhat-developer/odo/tests/helper"
|
||||
)
|
||||
|
||||
@@ -52,30 +52,25 @@ var _ = Describe("odo dev command tests", func() {
|
||||
Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse())
|
||||
})
|
||||
It("should show validation errors if the devfile is incorrect", func() {
|
||||
session := helper.CmdRunner("odo", "dev")
|
||||
defer session.Kill()
|
||||
helper.WaitForOutputToContain("Waiting for something to change", 180, 10, session)
|
||||
helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "kind: run", "kind: build")
|
||||
helper.WaitForOutputToContain(watch.PushErrorString, 180, 10, session)
|
||||
helper.RunDevMode(func(session *gexec.Session) {
|
||||
helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "kind: run", "kind: build")
|
||||
helper.WaitForOutputToContain("Error occurred on Push", 180, 10, session)
|
||||
})
|
||||
})
|
||||
It("should use the index information from previous push operation", func() {
|
||||
// Create a new file A
|
||||
fileAPath, fileAText := helper.CreateSimpleFile(commonVar.Context, "my-file-", ".txt")
|
||||
|
||||
// watch that project
|
||||
session := helper.CmdRunner("odo", "dev")
|
||||
defer session.Kill()
|
||||
helper.RunDevMode(func(session *gexec.Session) {
|
||||
// Change some other file B
|
||||
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "App started", "App is super started")
|
||||
|
||||
helper.WaitForOutputToContain("Waiting for something to change", 180, 10, session)
|
||||
podName := commonVar.CliRunner.GetRunningPodNameByComponent(cmpName, commonVar.Project)
|
||||
|
||||
// Change some other file B
|
||||
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "App started", "App is super started")
|
||||
|
||||
podName := commonVar.CliRunner.GetRunningPodNameByComponent(cmpName, commonVar.Project)
|
||||
|
||||
// File should exist, and its content should match what we initially set it to
|
||||
execResult := commonVar.CliRunner.Exec(podName, commonVar.Project, "cat", "/projects/"+filepath.Base(fileAPath))
|
||||
Expect(execResult).To(ContainSubstring(fileAText))
|
||||
// File should exist, and its content should match what we initially set it to
|
||||
execResult := commonVar.CliRunner.Exec(podName, commonVar.Project, "cat", "/projects/"+filepath.Base(fileAPath))
|
||||
Expect(execResult).To(ContainSubstring(fileAText))
|
||||
})
|
||||
})
|
||||
It("ensure that index information is updated", func() {
|
||||
// watch that project
|
||||
|
||||
@@ -76,10 +76,15 @@ var _ = Describe("odo list with devfile", func() {
|
||||
It("should show the language for 'Type' in odo list", func() {
|
||||
checkList(metadata.Language)
|
||||
})
|
||||
When("the component is pushed", func() {
|
||||
When("the component is pushed in dev mode", func() {
|
||||
var devSession helper.DevSession
|
||||
BeforeEach(func() {
|
||||
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
|
||||
devSession = helper.StartDevMode()
|
||||
})
|
||||
AfterEach(func() {
|
||||
devSession.Stop()
|
||||
})
|
||||
|
||||
It("should show the language for 'Type' in odo list", func() {
|
||||
checkList(metadata.Language)
|
||||
})
|
||||
@@ -96,7 +101,7 @@ var _ = Describe("odo list with devfile", func() {
|
||||
})
|
||||
When("the component is pushed", func() {
|
||||
BeforeEach(func() {
|
||||
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
|
||||
helper.Cmd("odo", "push").ShouldPass()
|
||||
})
|
||||
It("should show 'Not available' for 'Type' in odo list", func() {
|
||||
checkList(component.NotAvailable)
|
||||
|
||||
Reference in New Issue
Block a user