Skip to content

Commit

Permalink
Integration tests for odo dev running on podman (#6332)
Browse files Browse the repository at this point in the history
* Change signature of StartDevMode to use options structure

* Add tests for odo dev on podman

* Uncomment commented code

* Update Makefile

Co-authored-by: Armel Soro <[email protected]>

Co-authored-by: Armel Soro <[email protected]>
  • Loading branch information
feloy and rm3l authored Nov 24, 2022
1 parent 5660093 commit 120920f
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 212 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ GINKGO_FLAGS_ALL = $(GINKGO_TEST_ARGS) --randomize-all --slow-spec-threshold=$(S
GINKGO_FLAGS_AUTO = $(GINKGO_FLAGS_ALL) -p
# Flags for tests that may be run in parallel
GINKGO_FLAGS=$(GINKGO_FLAGS_ALL) -nodes=$(TEST_EXEC_NODES)
# Flags for tests that must not be run in parallel
GINKGO_FLAGS_ONE=$(GINKGO_FLAGS_ALL) -nodes=1
# GolangCi version for unit-validate test
GOLANGCI_LINT_VERSION=1.49.0

Expand Down Expand Up @@ -190,12 +192,16 @@ openshiftci-presubmit-unittests:

.PHONY: test-integration-cluster
test-integration-cluster:
$(RUN_GINKGO) $(GINKGO_FLAGS) --junit-report="test-integration.xml" --label-filter="!nocluster" tests/integration
$(RUN_GINKGO) $(GINKGO_FLAGS) --junit-report="test-integration.xml" --label-filter="!nocluster && !podman" tests/integration

.PHONY: test-integration-no-cluster
test-integration-no-cluster:
$(RUN_GINKGO) $(GINKGO_FLAGS_AUTO) --junit-report="test-integration-nc.xml" --label-filter=nocluster tests/integration

.PHONY: test-integration-podman
test-integration-podman:
$(RUN_GINKGO) $(GINKGO_FLAGS_ONE) --junit-report="test-integration-podman.xml" --label-filter=podman tests/integration

.PHONY: test-integration
test-integration: test-integration-no-cluster test-integration-cluster

Expand Down
2 changes: 1 addition & 1 deletion tests/e2escenarios/e2e_devfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = Describe("odo devfile supported tests", func() {
defer helper.Chdir(workingDir)
helper.Chdir(projectDirPath)
helper.Cmd("odo", "init", "--name", componentName, "--devfile", component, "--starter", starter).ShouldPass()
session, _, _, _, err := helper.StartDevMode(nil)
session, _, _, _, err := helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())
session.Stop()
session.WaitEnd()
Expand Down
8 changes: 4 additions & 4 deletions tests/e2escenarios/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var _ = Describe("E2E Test", func() {
var devSession helper.DevSession
var ports map[string]string

devSession, _, _, ports, err = helper.StartDevMode(nil)
devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js", "from updated Node.js")
Expect(err).ToNot(HaveOccurred())
_, _, _, err = devSession.WaitSync()
Expand Down Expand Up @@ -119,7 +119,7 @@ var _ = Describe("E2E Test", func() {
helper.MatchAllInOutput(stdout, []string{componentName, "nodejs", "Deploy"})

// start dev mode again
devSession, _, _, ports, err = helper.StartDevMode(nil)
devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())

// making changes to the project again
Expand Down Expand Up @@ -193,7 +193,7 @@ var _ = Describe("E2E Test", func() {
var devSession helper.DevSession
var ports map[string]string

devSession, _, _, ports, err = helper.StartDevMode(nil)
devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js", "from updated Node.js")
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -239,7 +239,7 @@ var _ = Describe("E2E Test", func() {
helper.MatchAllInOutput(stdout, []string{componentName, "nodejs", "Deploy"})

// start dev mode again
devSession, _, _, ports, err = helper.StartDevMode(nil)
devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())

// making changes to the project again
Expand Down
22 changes: 17 additions & 5 deletions tests/helper/helper_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,34 @@ type DevSession struct {
console *expect.Console
}

type DevSessionOpts struct {
EnvVars []string
CmdlineArgs []string
RunOnPodman bool
}

// StartDevMode starts a dev session with `odo dev`
// It returns a session structure, the contents of the standard and error outputs
// and the redirections endpoints to access ports opened by component
// when the dev mode is completely started
func StartDevMode(envvars []string, opts ...string) (DevSession, []byte, []byte, map[string]string, error) {

func StartDevMode(options DevSessionOpts) (DevSession, []byte, []byte, map[string]string, error) {
if options.RunOnPodman {
options.CmdlineArgs = append(options.CmdlineArgs, "--run-on", "podman")
options.EnvVars = append(options.EnvVars, "ODO_EXPERIMENTAL_MODE=true")
}
c, err := expect.NewConsole(expect.WithStdout(os.Stdout))
if err != nil {
return DevSession{}, nil, nil, nil, err
}

args := []string{"dev", "--random-ports"}
args = append(args, opts...)
args = append(args, options.CmdlineArgs...)
cmd := Cmd("odo", args...)
cmd.Cmd.Stdin = c.Tty()
cmd.Cmd.Stdout = c.Tty()
cmd.Cmd.Stderr = c.Tty()

session := cmd.AddEnv(envvars...).Runner().session
session := cmd.AddEnv(options.EnvVars...).Runner().session
WaitForOutputToContain("[Ctrl+c] - Exit", 360, 10, session)
result := DevSession{
session: session,
Expand Down Expand Up @@ -229,7 +238,10 @@ func (o DevSession) CheckNotSynced(timeout time.Duration) {
// The inside handler is passed the internal session pointer, the contents of the standard and error outputs,
// and a slice of strings - ports - giving the redirections in the form localhost:<port_number> to access ports opened by component
func RunDevMode(additionalOpts []string, envvars []string, inside func(session *gexec.Session, outContents []byte, errContents []byte, ports map[string]string)) error {
session, outContents, errContents, urls, err := StartDevMode(envvars, additionalOpts...)
session, outContents, errContents, urls, err := StartDevMode(DevSessionOpts{
EnvVars: envvars,
CmdlineArgs: additionalOpts,
})
if err != nil {
return err
}
Expand Down
17 changes: 17 additions & 0 deletions tests/helper/labels.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package helper

import (
"github.com/onsi/ginkgo/v2"
)

const (
LabelNoCluster = "nocluster"
LabelPodman = "podman"
)

func NeedsCluster(labels []string) bool {
for _, label := range labels {
if label == LabelNoCluster {
return false
}
if label == LabelPodman {
return false
}
}
return true
}

func LabelPodmanIf(value bool, args ...interface{}) []interface{} {
res := []interface{}{}
if value {
res = append(res, ginkgo.Label(LabelPodman))
}
res = append(res, args...)
return res
}
4 changes: 2 additions & 2 deletions tests/integration/cmd_add_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ status:

When("odo dev is run", func() {
BeforeEach(func() {
devSession, _, _, _, err = helper.StartDevMode(nil)
devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
Expand All @@ -265,7 +265,7 @@ status:

When("odo dev is run", func() {
BeforeEach(func() {
devSession, _, _, _, err = helper.StartDevMode(nil)
devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())
})

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ var _ = Describe("odo delete command tests", func() {
var devSession helper.DevSession
BeforeEach(func() {
var err error
devSession, _, _, _, err = helper.StartDevMode(nil)
devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())
defer func() {
devSession.Kill()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_describe_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ var _ = Describe("odo describe component command tests", func() {

BeforeEach(func() {
var err error
devSession, _, _, ports, err = helper.StartDevMode(nil)
devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).NotTo(HaveOccurred())
})

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_describe_list_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ var _ = Describe("odo describe/list binding command tests", func() {
var session helper.DevSession
BeforeEach(func() {
var err error
session, _, _, _, err = helper.StartDevMode(nil)
session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())
})

Expand Down
17 changes: 13 additions & 4 deletions tests/integration/cmd_dev_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ var _ = Describe("odo dev debug command tests", func() {
var ports map[string]string
BeforeEach(func() {
var err error
devSession, _, _, ports, err = helper.StartDevMode(nil, "--debug")
devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{
CmdlineArgs: []string{"--debug"},
})
Expect(err).ToNot(HaveOccurred())
})

Expand Down Expand Up @@ -97,7 +99,9 @@ var _ = Describe("odo dev debug command tests", func() {
devfileHandlerCtx.devfileHandler(filepath.Join(commonVar.Context, "devfile.yaml"))
}
var err error
session, stdout, stderr, ports, err = helper.StartDevMode(nil, "--debug")
session, stdout, stderr, ports, err = helper.StartDevMode(helper.DevSessionOpts{
CmdlineArgs: []string{"--debug"},
})
Expect(err).ToNot(HaveOccurred())
})

Expand Down Expand Up @@ -168,7 +172,10 @@ var _ = Describe("odo dev debug command tests", func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-composite-apply-commands.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"))
session, sessionOut, _, ports, err = helper.StartDevMode([]string{"PODMAN_CMD=echo"}, "--debug")
session, sessionOut, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{
EnvVars: []string{"PODMAN_CMD=echo"},
CmdlineArgs: []string{"--debug"},
})
Expect(err).ToNot(HaveOccurred())
})
It("should execute the composite apply commands successfully", func() {
Expand Down Expand Up @@ -254,7 +261,9 @@ var _ = Describe("odo dev debug command tests", func() {
devfileHandlerCtx.devfileHandler(filepath.Join(commonVar.Context, "devfile.yaml"))
}
var err error
session, stdout, stderr, ports, err = helper.StartDevMode(nil, "--debug")
session, stdout, stderr, ports, err = helper.StartDevMode(helper.DevSessionOpts{
CmdlineArgs: []string{"--debug"},
})
Expect(err).ToNot(HaveOccurred())
})

Expand Down
Loading

0 comments on commit 120920f

Please sign in to comment.