diff --git a/tests/documentation/user-guides/doc_user_guides_quickstart_test.go b/tests/documentation/user-guides/doc_user_guides_quickstart_test.go index a75e1051f37..b4b7f84f98c 100644 --- a/tests/documentation/user-guides/doc_user_guides_quickstart_test.go +++ b/tests/documentation/user-guides/doc_user_guides_quickstart_test.go @@ -89,13 +89,13 @@ var _ = Describe("User guides: Quickstart test", func() { Expect(diff).To(BeEmpty(), file) }) By("running odo dev", func() { - session, out, _, cmdEndpointsMap, err := helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err := helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).To(BeNil()) - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() args := []string{"dev"} - got := strings.ReplaceAll(string(out), commonVar.Context, "/home/user/quickstart-demo") - got = helper.ReplaceAllForwardedPorts(got, cmdEndpointsMap, map[string]string{"3000": "127.0.0.1:20001", "5858": "127.0.0.1:20002"}) + got := strings.ReplaceAll(devSession.StdOut, commonVar.Context, "/home/user/quickstart-demo") + got = helper.ReplaceAllForwardedPorts(got, devSession.Endpoints, map[string]string{"3000": "127.0.0.1:20001", "5858": "127.0.0.1:20002"}) got = strings.ReplaceAll(got, commonVar.Project, namespace) got = fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(got)) file := filepath.Join(commonNodeJSPath, "nodejs_odo_dev_output.mdx") @@ -137,13 +137,13 @@ var _ = Describe("User guides: Quickstart test", func() { Expect(diff).To(BeEmpty(), file) }) By("running odo dev", func() { - session, out, _, cmdEndpointsMap, err := helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err := helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).To(BeNil()) - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() args := []string{"dev"} - got := strings.ReplaceAll(string(out), commonVar.Context, "/home/user/quickstart-demo") - got = helper.ReplaceAllForwardedPorts(got, cmdEndpointsMap, map[string]string{"8080": "127.0.0.1:20001"}) + got := strings.ReplaceAll(devSession.StdOut, commonVar.Context, "/home/user/quickstart-demo") + got = helper.ReplaceAllForwardedPorts(got, devSession.Endpoints, map[string]string{"8080": "127.0.0.1:20001"}) got = strings.ReplaceAll(got, commonVar.Project, namespace) got = fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(got)) file := filepath.Join(commonGoPath, "go_odo_dev_output.mdx") @@ -193,13 +193,13 @@ var _ = Describe("User guides: Quickstart test", func() { Expect(diff).To(BeEmpty(), file) }) By("running odo dev", func() { - session, out, _, cmdEndpointsMap, err := helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err := helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).To(BeNil()) - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() args := []string{"dev"} - got := strings.ReplaceAll(string(out), commonVar.Context, "/home/user/quickstart-demo") - got = helper.ReplaceAllForwardedPorts(got, cmdEndpointsMap, map[string]string{"8080": "127.0.0.1:20001"}) + got := strings.ReplaceAll(devSession.StdOut, commonVar.Context, "/home/user/quickstart-demo") + got = helper.ReplaceAllForwardedPorts(got, devSession.Endpoints, map[string]string{"8080": "127.0.0.1:20001"}) got = strings.ReplaceAll(got, commonVar.Project, namespace) got = fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(got)) file := filepath.Join(commondotnetPath, "dotnet_odo_dev_output.mdx") @@ -241,13 +241,13 @@ var _ = Describe("User guides: Quickstart test", func() { Expect(diff).To(BeEmpty(), file) }) By("running odo dev", func() { - session, out, _, cmdEndpointsMap, err := helper.StartDevMode(helper.DevSessionOpts{TimeoutInSeconds: 420}) + devSession, err := helper.StartDevMode(helper.DevSessionOpts{TimeoutInSeconds: 420}) Expect(err).To(BeNil()) - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() args := []string{"dev"} - got := strings.ReplaceAll(string(out), commonVar.Context, "/home/user/quickstart-demo") - got = helper.ReplaceAllForwardedPorts(got, cmdEndpointsMap, map[string]string{"8080": "127.0.0.1:20001", "5858": "127.0.0.1:20002"}) + got := strings.ReplaceAll(devSession.StdOut, commonVar.Context, "/home/user/quickstart-demo") + got = helper.ReplaceAllForwardedPorts(got, devSession.Endpoints, map[string]string{"8080": "127.0.0.1:20001", "5858": "127.0.0.1:20002"}) got = strings.ReplaceAll(got, commonVar.Project, namespace) got = fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(got)) file := filepath.Join(commonGoPath, "java_odo_dev_output.mdx") diff --git a/tests/e2escenarios/e2e_test.go b/tests/e2escenarios/e2e_test.go index c121162cea9..e8559c4980b 100644 --- a/tests/e2escenarios/e2e_test.go +++ b/tests/e2escenarios/e2e_test.go @@ -98,27 +98,26 @@ var _ = Describe("E2E Test", func() { // "execute odo dev and add changes to application" var devSession helper.DevSession - var ports map[string]string - devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js Starter Application!", "runtime") - checkIfDevEnvIsUp(ports["3000"], "Hello from Node.js Starter Application!") + checkIfDevEnvIsUp(devSession.Endpoints["3000"], "Hello from Node.js Starter Application!") helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js", "from updated Node.js") - _, _, _, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) // "should update the changes" waitRemoteApp("http://127.0.0.1:3000", "Hello from updated Node.js Starter Application!", "runtime") - checkIfDevEnvIsUp(ports["3000"], "Hello from updated Node.js Starter Application!") + checkIfDevEnvIsUp(devSession.Endpoints["3000"], "Hello from updated Node.js Starter Application!") // "changes are made to the applications" helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from updated Node.js", "from Node.js app v2") - _, _, _, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) // "should deploy new changes" waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js app v2 Starter Application!", "runtime") - checkIfDevEnvIsUp(ports["3000"], "Hello from Node.js app v2 Starter Application!") + checkIfDevEnvIsUp(devSession.Endpoints["3000"], "Hello from Node.js app v2 Starter Application!") // "running odo list" stdout := helper.Cmd("odo", "list", "component").ShouldPass().Out() @@ -150,16 +149,16 @@ var _ = Describe("E2E Test", func() { helper.MatchAllInOutput(stdout, []string{componentName, "nodejs", "Deploy"}) // start dev mode again - devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) // making changes to the project again helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js app v2", "from Node.js app v3") - _, _, _, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) // "should update the changes" waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js app v3 Starter Application!", "runtime") - checkIfDevEnvIsUp(ports["3000"], "Hello from Node.js app v3 Starter Application!") + checkIfDevEnvIsUp(devSession.Endpoints["3000"], "Hello from Node.js app v3 Starter Application!") // should list both dev,deploy stdout = helper.Cmd("odo", "list", "component").ShouldPass().Out() @@ -226,28 +225,26 @@ var _ = Describe("E2E Test", func() { // "execute odo dev and add changes to application" var devSession helper.DevSession - var ports map[string]string - var out []byte - devSession, out, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) - Expect(out).ToNot(BeEmpty()) + Expect(devSession.StdOut).ToNot(BeEmpty()) waitRemoteApp(AppLocalURL, "Hello World!", "tools") - checkIfDevEnvIsUp(ports[AppPort], "Hello World!") + checkIfDevEnvIsUp(devSession.Endpoints[AppPort], "Hello World!") helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "com", "example", "demo", "DemoApplication.java"), "Hello World!", "Hello updated World!") - _, _, _, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) // "should update the changes" waitRemoteApp(AppLocalURL, "Hello updated World!", "tools") - checkIfDevEnvIsUp(ports[AppPort], "Hello updated World!") + checkIfDevEnvIsUp(devSession.Endpoints[AppPort], "Hello updated World!") // "changes are made to the applications" helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "com", "example", "demo", "DemoApplication.java"), "Hello updated World!", "Hello from an updated World!") - _, _, _, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) // "should deploy new changes" waitRemoteApp(AppLocalURL, "Hello from an updated World!", "tools") - checkIfDevEnvIsUp(ports[AppPort], "Hello from an updated World!") + checkIfDevEnvIsUp(devSession.Endpoints[AppPort], "Hello from an updated World!") // "running odo list" stdout := helper.Cmd("odo", "list", "component").ShouldPass().Out() @@ -279,17 +276,17 @@ var _ = Describe("E2E Test", func() { helper.MatchAllInOutput(stdout, []string{componentName, "springboot", "Deploy"}) // start dev mode again - devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) // making changes to the project again helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "com", "example", "demo", "DemoApplication.java"), "Hello from an updated World!", "Hello from an updated v2 World!") - _, _, _, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) // "should update the changes" waitRemoteApp(AppLocalURL, "Hello from an updated v2 World!", "tools") - checkIfDevEnvIsUp(ports[AppPort], "Hello from an updated v2 World!") + checkIfDevEnvIsUp(devSession.Endpoints[AppPort], "Hello from an updated v2 World!") // should list both dev,deploy stdout = helper.Cmd("odo", "list", "component").ShouldPass().Out() @@ -371,34 +368,33 @@ var _ = Describe("E2E Test", func() { // "execute odo dev and add changes to application" var devSession helper.DevSession - var ports map[string]string - var out []byte - devSession, out, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: []string{"--debug"}, }) Expect(err).ToNot(HaveOccurred()) - Expect(out).ToNot(BeEmpty()) + Expect(devSession.StdOut).ToNot(BeEmpty()) waitRemoteApp(LocalAppURL, "Hello from Node.js Starter Application!", "runtime") - checkIfDevEnvIsUp(ports[AppPort], "Hello from Node.js Starter Application!") - checkIfDevEnvIsUp(ports[DebugPort], "WebSockets request was expected") + checkIfDevEnvIsUp(devSession.Endpoints[AppPort], "Hello from Node.js Starter Application!") + checkIfDevEnvIsUp(devSession.Endpoints[DebugPort], "WebSockets request was expected") helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js", "from updated Node.js") - _, _, _, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) // "should update the changes" waitRemoteApp(LocalAppURL, "Hello from updated Node.js Starter Application!", "runtime") - checkIfDevEnvIsUp(ports[AppPort], "Hello from updated Node.js Starter Application!") - checkIfDevEnvIsUp(ports[DebugPort], "WebSockets request was expected") + checkIfDevEnvIsUp(devSession.Endpoints[AppPort], "Hello from updated Node.js Starter Application!") + checkIfDevEnvIsUp(devSession.Endpoints[DebugPort], "WebSockets request was expected") // "changes are made to the applications" helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from updated Node.js", "from Node.js app v2") - _, _, _, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) // "should deploy new changes" waitRemoteApp(LocalAppURL, "Hello from Node.js app v2 Starter Application!", "runtime") - checkIfDevEnvIsUp(ports[AppPort], "Hello from Node.js app v2 Starter Application!") - checkIfDevEnvIsUp(ports[DebugPort], "WebSockets request was expected") + checkIfDevEnvIsUp(devSession.Endpoints[AppPort], "Hello from Node.js app v2 Starter Application!") + checkIfDevEnvIsUp(devSession.Endpoints[DebugPort], "WebSockets request was expected") // "running odo list" stdout := helper.Cmd("odo", "list", "component").ShouldPass().Out() @@ -488,29 +484,28 @@ var _ = Describe("E2E Test", func() { // // "execute odo dev and add changes to application" var devSession helper.DevSession - var ports map[string]string - devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) // "send data" - _, err = receiveData(fmt.Sprintf(ports["8080"] + "/api/user")) + _, err = receiveData(fmt.Sprintf(devSession.Endpoints["8080"] + "/api/user")) Expect(err).ToNot(BeNil()) // should fail as application is not connected to DB //add binding information (binding as ENV) helper.Cmd("odo", "add", "binding", "--name", bindingName, "--service", "cluster-example-initdb", "--bind-as-files=false").ShouldPass() // Get new random port after restart - _, _, ports, err = devSession.WaitRestartPortforward() + err = devSession.WaitRestartPortforward() Expect(err).ToNot(HaveOccurred()) // "send data" waitRemoteApp("http://127.0.0.1:8080/ping", "pong", "runtime") - data := sendDataEntry(ports["8080"]) + data := sendDataEntry(devSession.Endpoints["8080"]) Expect(data["message"]).To(Equal("User created successfully")) // "get all data" - rec, err := receiveData(fmt.Sprintf(ports["8080"] + "/api/user")) + rec, err := receiveData(fmt.Sprintf(devSession.Endpoints["8080"] + "/api/user")) Expect(err).To(BeNil()) helper.MatchAllInOutput(rec, []string{"id", "1", "name", "joe", "location", "tokyo", "age", "23"}) @@ -525,7 +520,7 @@ var _ = Describe("E2E Test", func() { // remove bindings and check devfile to not contain binding info helper.Cmd("odo", "remove", "binding", "--name", bindingName).ShouldPass() - _, _, _, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).To(BeNil()) Eventually(func() string { return helper.Cmd("odo", "describe", "binding").ShouldRun().Out() }). WithTimeout(120 * time.Second). diff --git a/tests/helper/helper_dev.go b/tests/helper/helper_dev.go index 7a24be3b20b..428d71bc74d 100644 --- a/tests/helper/helper_dev.go +++ b/tests/helper/helper_dev.go @@ -110,10 +110,13 @@ import ( */ type DevSession struct { - session *gexec.Session - stopped bool - console *expect.Console - address string + session *gexec.Session + stopped bool + console *expect.Console + address string + StdOut string + ErrOut string + Endpoints map[string]string } type DevSessionOpts struct { @@ -131,13 +134,13 @@ type DevSessionOpts struct { // 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(options DevSessionOpts) (devSession DevSession, out []byte, errOut []byte, endpoints map[string]string, err error) { +func StartDevMode(options DevSessionOpts) (devSession DevSession, err error) { if options.RunOnPodman { options.CmdlineArgs = append(options.CmdlineArgs, "--platform", "podman") } c, err := expect.NewConsole(expect.WithStdout(os.Stdout)) if err != nil { - return DevSession{}, nil, nil, nil, err + return DevSession{}, err } args := []string{"dev"} @@ -174,13 +177,16 @@ func StartDevMode(options DevSessionOpts) (devSession DevSession, out []byte, er errContents := session.Err.Contents() err = session.Out.Clear() if err != nil { - return DevSession{}, nil, nil, nil, err + return DevSession{}, err } err = session.Err.Clear() if err != nil { - return DevSession{}, nil, nil, nil, err + return DevSession{}, err } - return result, outContents, errContents, getPorts(string(outContents), options.CustomAddress), nil + result.StdOut = string(outContents) + result.ErrOut = string(errContents) + result.Endpoints = getPorts(string(outContents), options.CustomAddress) + return result, nil } @@ -231,33 +237,40 @@ func (o DevSession) WaitEnd() { // WaitSync waits for the synchronization of files to be finished // It returns the contents of the standard and error outputs // and the list of forwarded ports -// since the end of the dev mode or the last time WaitSync/GetInfo has been called -func (o DevSession) WaitSync() ([]byte, []byte, map[string]string, error) { +// since the end of the dev mode or the last time WaitSync/UpdateInfo has been called +func (o *DevSession) WaitSync() error { WaitForOutputToContainOne([]string{"Pushing files...", "Updating Component..."}, 180, 10, o.session) WaitForOutputToContain("Dev mode", 240, 10, o.session) - return o.GetInfo() + return o.UpdateInfo() } -func (o DevSession) WaitRestartPortforward() ([]byte, []byte, map[string]string, error) { +func (o *DevSession) WaitRestartPortforward() error { WaitForOutputToContain("Forwarding from", 240, 10, o.session) - return o.GetInfo() + return o.UpdateInfo() } -// GetInfo returns the contents of the standard and error outputs +// UpdateInfo returns the contents of the standard and error outputs // and the list of forwarded ports -// since the end of the dev mode or the last time WaitSync/GetInfo has been called -func (o DevSession) GetInfo() ([]byte, []byte, map[string]string, error) { +// since the end of the dev mode or the last time WaitSync/UpdateInfo has been called +func (o *DevSession) UpdateInfo() error { outContents := o.session.Out.Contents() errContents := o.session.Err.Contents() err := o.session.Out.Clear() if err != nil { - return nil, nil, nil, err + return err } err = o.session.Err.Clear() if err != nil { - return nil, nil, nil, err + return err } - return outContents, errContents, getPorts(string(outContents), o.address), nil + o.StdOut = string(outContents) + o.ErrOut = string(errContents) + endpoints := getPorts(o.StdOut, o.address) + if len(endpoints) != 0 { + // when pod was restarted and port forwarding is done again + o.Endpoints = endpoints + } + return nil } func (o DevSession) CheckNotSynced(timeout time.Duration) { @@ -269,9 +282,9 @@ func (o DevSession) CheckNotSynced(timeout time.Duration) { // RunDevMode runs a dev session and executes the `inside` code when the dev mode is completely started // 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: to access ports opened by component -func RunDevMode(options DevSessionOpts, inside func(session *gexec.Session, outContents []byte, errContents []byte, ports map[string]string)) error { +func RunDevMode(options DevSessionOpts, inside func(session *gexec.Session, outContents string, errContents string, ports map[string]string)) error { - session, outContents, errContents, urls, err := StartDevMode(options) + session, err := StartDevMode(options) if err != nil { return err } @@ -279,7 +292,7 @@ func RunDevMode(options DevSessionOpts, inside func(session *gexec.Session, outC session.Stop() session.WaitEnd() }() - inside(session.session, outContents, errContents, urls) + inside(session.session, session.StdOut, session.ErrOut, session.Endpoints) return nil } @@ -288,7 +301,7 @@ func RunDevMode(options DevSessionOpts, inside func(session *gexec.Session, outC // this function is helpful in such cases. // If stopSessionAfter is false, it is up to the caller to stop the DevSession returned. // TODO(pvala): Modify StartDevMode to take substring arg into account, and replace this method with it. -func WaitForDevModeToContain(options DevSessionOpts, substring string, stopSessionAfter bool, checkErrOut bool) (DevSession, []byte, []byte, error) { +func WaitForDevModeToContain(options DevSessionOpts, substring string, stopSessionAfter bool, checkErrOut bool) (DevSession, error) { args := []string{"dev", "--random-ports"} args = append(args, options.CmdlineArgs...) if options.RunOnPodman { @@ -318,13 +331,16 @@ func WaitForDevModeToContain(options DevSessionOpts, substring string, stopSessi errContents := session.Err.Contents() err := session.Out.Clear() if err != nil { - return DevSession{}, nil, nil, err + return DevSession{}, err } err = session.Err.Clear() if err != nil { - return DevSession{}, nil, nil, err + return DevSession{}, err } - return result, outContents, errContents, nil + result.StdOut = string(outContents) + result.ErrOut = string(errContents) + result.Endpoints = getPorts(result.StdOut, options.CustomAddress) + return result, nil } // getPorts returns a map of ports redirected depending on the information in s diff --git a/tests/integration/cmd_add_binding_test.go b/tests/integration/cmd_add_binding_test.go index ad927b127c2..2832d1e2554 100644 --- a/tests/integration/cmd_add_binding_test.go +++ b/tests/integration/cmd_add_binding_test.go @@ -249,7 +249,7 @@ status: When("odo dev is run", func() { BeforeEach(func() { - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { @@ -265,7 +265,7 @@ status: When("odo dev is run", func() { BeforeEach(func() { - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) diff --git a/tests/integration/cmd_delete_test.go b/tests/integration/cmd_delete_test.go index 00ab5cfaff3..89b2ba3f86b 100644 --- a/tests/integration/cmd_delete_test.go +++ b/tests/integration/cmd_delete_test.go @@ -229,7 +229,7 @@ var _ = Describe("odo delete command tests", func() { var devSession helper.DevSession BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -552,7 +552,7 @@ var _ = Describe("odo delete command tests", func() { Expect(commonVar.CliRunner.Run(getSVCArgs...).Out.Contents()).To(ContainSubstring(serviceName)) var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) devSession.Kill() diff --git a/tests/integration/cmd_describe_component_test.go b/tests/integration/cmd_describe_component_test.go index 19b1f91d5e5..3f032fdf8dc 100644 --- a/tests/integration/cmd_describe_component_test.go +++ b/tests/integration/cmd_describe_component_test.go @@ -262,7 +262,6 @@ var _ = Describe("odo describe component command tests", func() { debug := debug When(fmt.Sprintf("running odo dev (podman=%s,debug=%s)", strconv.FormatBool(podman), strconv.FormatBool(debug)), helper.LabelPodmanIf(podman, func() { var devSession helper.DevSession - var ports map[string]string BeforeEach(func() { opts := helper.DevSessionOpts{RunOnPodman: podman} @@ -274,7 +273,7 @@ var _ = Describe("odo describe component command tests", func() { } } var err error - devSession, _, _, ports, err = helper.StartDevMode(opts) + devSession, err = helper.StartDevMode(opts) Expect(err).NotTo(HaveOccurred()) }) @@ -296,19 +295,19 @@ var _ = Describe("odo describe component command tests", func() { Expect(stdout).To(ContainSubstring("Running on:")) Expect(stdout).To(ContainSubstring("Forwarded ports")) if podman { - Expect(stdout).To(ContainSubstring("[podman] 127.0.0.1:%s -> runtime:3000\n Name: http-3000", ports["3000"][len("127.0.0.1:"):])) + Expect(stdout).To(ContainSubstring("[podman] 127.0.0.1:%s -> runtime:3000\n Name: http-3000", devSession.Endpoints["3000"][len("127.0.0.1:"):])) if debug { Expect(stdout).To( ContainSubstring("127.0.0.1:%s -> runtime:5858\n Name: debug\n Exposure: none\n Debug: true", - ports["5858"][len("127.0.0.1:"):])) + devSession.Endpoints["5858"][len("127.0.0.1:"):])) } Expect(stdout).NotTo(ContainSubstring("[cluster] 127.0.0.1:")) Expect(stdout).To(ContainSubstring("podman: Dev")) Expect(stdout).NotTo(ContainSubstring("cluster: ")) } else { - Expect(stdout).To(ContainSubstring("[cluster] 127.0.0.1:%s -> runtime:3000\n Name: http-3000", ports["3000"][len("127.0.0.1:"):])) + Expect(stdout).To(ContainSubstring("[cluster] 127.0.0.1:%s -> runtime:3000\n Name: http-3000", devSession.Endpoints["3000"][len("127.0.0.1:"):])) if debug { - Expect(stdout).To(ContainSubstring("[cluster] 127.0.0.1:%s -> runtime:5858\n Name: debug\n Exposure: none\n Debug: true", ports["5858"][len("127.0.0.1:"):])) + Expect(stdout).To(ContainSubstring("[cluster] 127.0.0.1:%s -> runtime:5858\n Name: debug\n Exposure: none\n Debug: true", devSession.Endpoints["5858"][len("127.0.0.1:"):])) } Expect(stdout).NotTo(ContainSubstring("[podman] 127.0.0.1:")) Expect(stdout).To(ContainSubstring("cluster: Dev")) @@ -374,7 +373,7 @@ var _ = Describe("odo describe component command tests", func() { helper.JsonPathContentIs(stdout, "devForwardedPorts.0.portName", "http-3000") helper.JsonPathContentIs(stdout, "devForwardedPorts.0.isDebug", "false") helper.JsonPathContentIs(stdout, "devForwardedPorts.0.localAddress", "127.0.0.1") - helper.JsonPathContentIs(stdout, "devForwardedPorts.0.localPort", ports["3000"][len("127.0.0.1:"):]) + helper.JsonPathContentIs(stdout, "devForwardedPorts.0.localPort", devSession.Endpoints["3000"][len("127.0.0.1:"):]) helper.JsonPathContentIs(stdout, "devForwardedPorts.0.containerPort", "3000") helper.JsonPathDoesNotExist(stdout, "devForwardedPorts.0.exposure") if debug { @@ -382,7 +381,7 @@ var _ = Describe("odo describe component command tests", func() { helper.JsonPathContentIs(stdout, "devForwardedPorts.1.portName", "debug") helper.JsonPathContentIs(stdout, "devForwardedPorts.1.isDebug", "true") helper.JsonPathContentIs(stdout, "devForwardedPorts.1.localAddress", "127.0.0.1") - helper.JsonPathContentIs(stdout, "devForwardedPorts.1.localPort", ports["5858"][len("127.0.0.1:"):]) + helper.JsonPathContentIs(stdout, "devForwardedPorts.1.localPort", devSession.Endpoints["5858"][len("127.0.0.1:"):]) helper.JsonPathContentIs(stdout, "devForwardedPorts.1.containerPort", "5858") helper.JsonPathContentIs(stdout, "devForwardedPorts.1.exposure", "none") } @@ -575,7 +574,7 @@ var _ = Describe("odo describe component command tests", func() { helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", ctx.devfile)).ShouldPass() var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{RunOnPodman: podman}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{RunOnPodman: podman}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { diff --git a/tests/integration/cmd_describe_list_binding_test.go b/tests/integration/cmd_describe_list_binding_test.go index e2bd53e5e3f..31886787884 100644 --- a/tests/integration/cmd_describe_list_binding_test.go +++ b/tests/integration/cmd_describe_list_binding_test.go @@ -711,7 +711,7 @@ var _ = Describe("odo describe/list binding command tests", func() { var session helper.DevSession BeforeEach(func() { var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + session, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) diff --git a/tests/integration/cmd_dev_debug_test.go b/tests/integration/cmd_dev_debug_test.go index bcf858952f4..088bcbd7320 100644 --- a/tests/integration/cmd_dev_debug_test.go +++ b/tests/integration/cmd_dev_debug_test.go @@ -44,10 +44,7 @@ var _ = Describe("odo dev debug command tests", func() { }) When("running odo dev with debug flag and custom port mapping for port forwarding", helper.LabelPodmanIf(podman, func() { var ( - devSession helper.DevSession - ports map[string]string - ) - var ( + devSession helper.DevSession LocalPort, LocalDebugPort int ) const ( @@ -63,7 +60,7 @@ var _ = Describe("odo dev debug command tests", func() { opts = append(opts, "--forward-localhost") } var err error - devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: opts, NoRandomPorts: true, RunOnPodman: podman, @@ -78,12 +75,12 @@ var _ = Describe("odo dev debug command tests", func() { It("should connect to relevant custom ports forwarded", func() { By("connecting to the application port", func() { - helper.HttpWaitForWithStatus(fmt.Sprintf("http://%s", ports[ContainerPort]), "Hello from Node.js Starter Application!", 12, 5, 200) + helper.HttpWaitForWithStatus(fmt.Sprintf("http://%s", devSession.Endpoints[ContainerPort]), "Hello from Node.js Starter Application!", 12, 5, 200) }) By("expecting a ws connection when tried to connect on default debug port locally", func() { // 400 response expected because the endpoint expects a websocket request and we are doing a HTTP GET // We are just using this to validate if nodejs agent is listening on the other side - url := fmt.Sprintf("http://%s", ports[ContainerDebugPort]) + url := fmt.Sprintf("http://%s", devSession.Endpoints[ContainerDebugPort]) Expect(url).To(ContainSubstring(strconv.Itoa(LocalDebugPort))) helper.HttpWaitForWithStatus(url, "WebSockets request was expected", 12, 5, 400) @@ -93,7 +90,7 @@ var _ = Describe("odo dev debug command tests", func() { When("running odo dev with debug flag", helper.LabelPodmanIf(podman, func() { var devSession helper.DevSession - var ports map[string]string + BeforeEach(func() { var err error opts := helper.DevSessionOpts{ @@ -103,7 +100,7 @@ var _ = Describe("odo dev debug command tests", func() { if podman { opts.CmdlineArgs = append(opts.CmdlineArgs, "--forward-localhost") } - devSession, _, _, ports, err = helper.StartDevMode(opts) + devSession, err = helper.StartDevMode(opts) Expect(err).ToNot(HaveOccurred()) }) @@ -114,12 +111,12 @@ var _ = Describe("odo dev debug command tests", func() { It("should connect to relevant ports forwarded", func() { By("connecting to the application port", func() { - helper.HttpWaitForWithStatus("http://"+ports["3000"], "Hello from Node.js Starter Application!", 12, 5, 200) + helper.HttpWaitForWithStatus("http://"+devSession.Endpoints["3000"], "Hello from Node.js Starter Application!", 12, 5, 200) }) By("expecting a ws connection when tried to connect on default debug port locally", func() { // 400 response expected because the endpoint expects a websocket request and we are doing a HTTP GET // We are just using this to validate if nodejs agent is listening on the other side - helper.HttpWaitForWithStatus("http://"+ports["5858"], "WebSockets request was expected", 12, 5, 400) + helper.HttpWaitForWithStatus("http://"+devSession.Endpoints["5858"], "WebSockets request was expected", 12, 5, 400) }) }) @@ -136,7 +133,7 @@ var _ = Describe("odo dev debug command tests", func() { for _, podman := range []bool{false, true} { podman := podman When("creating nodejs component, doing odo dev and run command has dev.odo.push.path attribute", helper.LabelPodmanIf(podman, func() { - var session helper.DevSession + var devSession helper.DevSession var devStarted bool BeforeEach(func() { helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", @@ -149,7 +146,7 @@ var _ = Describe("odo dev debug command tests", func() { helper.ReplaceString("package.json", "node server.js", "node server-debug/server.js") var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, CmdlineArgs: []string{"--debug"}, }) @@ -158,8 +155,8 @@ var _ = Describe("odo dev debug command tests", func() { }) AfterEach(func() { if devStarted { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() } }) @@ -196,10 +193,8 @@ var _ = Describe("odo dev debug command tests", func() { podman := podman When("a composite command is used as debug command - "+devfileHandlerCtx.name, helper.LabelPodmanIf(podman, func() { var devfileCmpName string - var session helper.DevSession - var stdout []byte - var stderr []byte - var ports map[string]string + var devSession helper.DevSession + BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExampleDevFile( @@ -218,18 +213,18 @@ var _ = Describe("odo dev debug command tests", func() { if podman { opts.CmdlineArgs = append(opts.CmdlineArgs, "--forward-localhost") } - session, stdout, stderr, ports, err = helper.StartDevMode(opts) + devSession, err = helper.StartDevMode(opts) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should run successfully", func() { By("verifying from the output that all commands have been executed", func() { - helper.MatchAllInOutput(string(stdout), []string{ + helper.MatchAllInOutput(devSession.StdOut, []string{ "Building your application in container", "Executing the application (command: mkdir)", "Executing the application (command: echo)", @@ -239,7 +234,7 @@ var _ = Describe("odo dev debug command tests", func() { }) By("verifying that any command that did not succeed in the middle has logged such information correctly", func() { - helper.MatchAllInOutput(string(stderr), []string{ + helper.MatchAllInOutput(devSession.ErrOut, []string{ "Devfile command \"echo\" exited with an error status", "intentional-error-message", }) @@ -248,8 +243,8 @@ var _ = Describe("odo dev debug command tests", func() { By("building the application only once", func() { // Because of the Spinner, the "Building your application in container" is printed twice in the captured stdout. // The bracket allows to match the last occurrence with the command execution timing information. - Expect(strings.Count(string(stdout), "Building your application in container (command: install) [")). - To(BeNumerically("==", 1), "\nOUTPUT: "+string(stdout)+"\n") + Expect(strings.Count(devSession.StdOut, "Building your application in container (command: install) [")). + To(BeNumerically("==", 1), "\nOUTPUT: "+devSession.StdOut+"\n") }) By("verifying that the command did run successfully", func() { @@ -262,7 +257,7 @@ var _ = Describe("odo dev debug command tests", func() { By("expecting a ws connection when tried to connect on default debug port locally", func() { // 400 response expected because the endpoint expects a websocket request and we are doing a HTTP GET // We are just using this to validate if nodejs agent is listening on the other side - helper.HttpWaitForWithStatus("http://"+ports["5858"], "WebSockets request was expected", 12, 5, 400) + helper.HttpWaitForWithStatus("http://"+devSession.Endpoints["5858"], "WebSockets request was expected", 12, 5, 400) }) }) })) @@ -271,10 +266,8 @@ var _ = Describe("odo dev debug command tests", func() { When("a composite apply command is used as debug command", func() { deploymentNames := []string{"my-openshift-component", "my-k8s-component"} - var session helper.DevSession - var sessionOut []byte - var err error - var ports map[string]string + var devSession helper.DevSession + const ( DEVFILE_DEBUG_PORT = "5858" ) @@ -285,7 +278,8 @@ var _ = Describe("odo dev debug command tests", func() { filepath.Join("source", "devfiles", "nodejs", "devfile-composite-apply-commands.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"), cmpName) - session, sessionOut, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + var err error + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ EnvVars: []string{"PODMAN_CMD=echo"}, CmdlineArgs: []string{"--debug"}, }) @@ -297,15 +291,15 @@ var _ = Describe("odo dev debug command tests", func() { helper.MatchAllInOutput(string(out), deploymentNames) } checkImageBuilt := func() { - Expect(string(sessionOut)).To(ContainSubstring("Building & Pushing Image")) - Expect(string(sessionOut)).To(ContainSubstring("build -t quay.io/unknown-account/myimage -f " + filepath.Join(commonVar.Context, "Dockerfile ") + commonVar.Context)) - Expect(string(sessionOut)).To(ContainSubstring("push quay.io/unknown-account/myimage")) + Expect(devSession.StdOut).To(ContainSubstring("Building & Pushing Image")) + Expect(devSession.StdOut).To(ContainSubstring("build -t quay.io/unknown-account/myimage -f " + filepath.Join(commonVar.Context, "Dockerfile ") + commonVar.Context)) + Expect(devSession.StdOut).To(ContainSubstring("push quay.io/unknown-account/myimage")) } checkWSConnection := func() { // 400 response expected because the endpoint expects a websocket request and we are doing a HTTP GET // We are just using this to validate if nodejs agent is listening on the other side - helper.HttpWaitForWithStatus("http://"+ports[DEVFILE_DEBUG_PORT], "WebSockets request was expected", 12, 5, 400) + helper.HttpWaitForWithStatus("http://"+devSession.Endpoints[DEVFILE_DEBUG_PORT], "WebSockets request was expected", 12, 5, 400) } By("expecting a ws connection when tried to connect on default debug port locally", func() { checkWSConnection() @@ -322,7 +316,7 @@ var _ = Describe("odo dev debug command tests", func() { By("checking odo dev watches correctly", func() { // making changes to the project again helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js Starter Application", "from the new Node.js Starter Application") - _, _, _, err = session.WaitSync() + err := devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) checkDeploymentExists() checkImageBuilt() @@ -330,8 +324,8 @@ var _ = Describe("odo dev debug command tests", func() { }) By("cleaning up the resources on ending the session", func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() out := commonVar.CliRunner.Run("get", "deployments").Out.Contents() helper.DontMatchAllInOutput(string(out), deploymentNames) }) @@ -358,12 +352,10 @@ var _ = Describe("odo dev debug command tests", func() { podman := podman When("running build and debug commands as composite in different containers and a shared volume - "+devfileHandlerCtx.name, helper.LabelPodmanIf(podman, func() { var devfileCmpName string - var session helper.DevSession - var stdout []byte - var stderr []byte - var ports map[string]string + var devSession helper.DevSession + BeforeEach(func() { - //TODO(rm3l): For some reason, this does not work on Podman + // TODO(rm3l): For some reason, this does not work on Podman if podman { Skip("Does not work on Podman due to permission issues related in the volume mount path: /bin/sh: /artifacts/build-result: Permission denied") } @@ -384,18 +376,18 @@ var _ = Describe("odo dev debug command tests", func() { if podman { opts.CmdlineArgs = append(opts.CmdlineArgs, "--forward-localhost") } - session, stdout, stderr, ports, err = helper.StartDevMode(opts) + devSession, err = helper.StartDevMode(opts) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should run successfully", func() { By("verifying from the output that all commands have been executed", func() { - helper.MatchAllInOutput(string(stdout), []string{ + helper.MatchAllInOutput(devSession.StdOut, []string{ "Building your application in container (command: mkdir)", "Building your application in container (command: sleep-cmd-build)", "Building your application in container (command: build-cmd)", @@ -407,7 +399,7 @@ var _ = Describe("odo dev debug command tests", func() { }) By("verifying that any command that did not succeed in the middle has logged such information correctly", func() { - helper.MatchAllInOutput(string(stderr), []string{ + helper.MatchAllInOutput(devSession.ErrOut, []string{ "Devfile command \"echo-with-error\" exited with an error status", "intentional-error-message", }) @@ -416,10 +408,10 @@ var _ = Describe("odo dev debug command tests", func() { By("building the application only once per exec command in the build command", func() { // Because of the Spinner, the "Building your application in container" is printed twice in the captured stdout. // The bracket allows to match the last occurrence with the command execution timing information. - out := string(stdout) + out := devSession.StdOut for _, cmd := range []string{"mkdir", "sleep-cmd-build", "build-cmd"} { Expect(strings.Count(out, fmt.Sprintf("Building your application in container (command: %s) [", cmd))). - To(BeNumerically("==", 1), "\nOUTPUT: "+string(stdout)+"\n") + To(BeNumerically("==", 1), "\nOUTPUT: "+devSession.StdOut+"\n") } }) @@ -433,7 +425,7 @@ var _ = Describe("odo dev debug command tests", func() { By("expecting a ws connection when tried to connect on default debug port locally", func() { // 400 response expected because the endpoint expects a websocket request and we are doing a HTTP GET // We are just using this to validate if nodejs agent is listening on the other side - helper.HttpWaitForWithStatus("http://"+ports["5858"], "WebSockets request was expected", 12, 5, 400) + helper.HttpWaitForWithStatus("http://"+devSession.Endpoints["5858"], "WebSockets request was expected", 12, 5, 400) }) }) })) @@ -450,7 +442,7 @@ var _ = Describe("odo dev debug command tests", func() { }) It("should log error about missing debug command when running odo dev --debug", func() { - devSession, _, stderr, _, err := helper.StartDevMode(helper.DevSessionOpts{ + devSession, err := helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, CmdlineArgs: []string{"--debug"}, }) @@ -459,7 +451,7 @@ var _ = Describe("odo dev debug command tests", func() { devSession.Stop() devSession.WaitEnd() }() - Expect(string(stderr)).To(ContainSubstring("Missing default debug command")) + Expect(devSession.ErrOut).To(ContainSubstring("Missing default debug command")) }) })) } @@ -478,10 +470,8 @@ var _ = Describe("odo dev debug command tests", func() { When("running odo dev with some components not referenced in the Devfile", func() { var devSession helper.DevSession - var stdout, stderr string BeforeEach(func() { - var bOut, bErr []byte var err error var envvars []string if podman { @@ -493,14 +483,12 @@ var _ = Describe("odo dev debug command tests", func() { if podman { args = append(args, "--forward-localhost") } - devSession, bOut, bErr, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: args, EnvVars: envvars, RunOnPodman: podman, }) Expect(err).ShouldNot(HaveOccurred()) - stdout = string(bOut) - stderr = string(bErr) }) AfterEach(func() { @@ -512,7 +500,7 @@ var _ = Describe("odo dev debug command tests", func() { It("should create the appropriate resources", func() { if podman { - k8sOcComponents := helper.ExtractK8sAndOcComponentsFromOutputOnPodman(stderr) + k8sOcComponents := helper.ExtractK8sAndOcComponentsFromOutputOnPodman(devSession.ErrOut) By("handling Kubernetes/OpenShift components that would have been created automatically", func() { Expect(k8sOcComponents).Should(ContainElements( "k8s-deploybydefault-true-and-referenced", @@ -542,7 +530,7 @@ var _ = Describe("odo dev debug command tests", func() { "ocp-deploybydefault-true-and-referenced", "ocp-deploybydefault-true-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) By("automatically applying non-referenced Kubernetes/OpenShift components with deployByDefault not set", func() { @@ -550,7 +538,7 @@ var _ = Describe("odo dev debug command tests", func() { "k8s-deploybydefault-not-set-and-not-referenced", "ocp-deploybydefault-not-set-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) By("not applying Kubernetes/OpenShift components with deployByDefault=false", func() { @@ -560,11 +548,11 @@ var _ = Describe("odo dev debug command tests", func() { "ocp-deploybydefault-false-and-referenced", "ocp-deploybydefault-false-and-not-referenced", } { - Expect(stdout).ShouldNot(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("Creating resource Pod/%s", l)) } }) By("not applying referenced Kubernetes/OpenShift components with deployByDefault unset", func() { - Expect(stdout).ShouldNot(ContainSubstring("Creating resource Pod/k8s-deploybydefault-not-set-and-referenced")) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("Creating resource Pod/k8s-deploybydefault-not-set-and-referenced")) }) } @@ -578,32 +566,30 @@ var _ = Describe("odo dev debug command tests", func() { "autobuild-true-and-referenced", "autobuild-true-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) } }) By("automatically applying non-referenced Image components with autoBuild not set", func() { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:autobuild-not-set-and-not-referenced", imageMessagePrefix)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:autobuild-not-set-and-not-referenced", imageMessagePrefix)) }) By("not applying image components with autoBuild=false", func() { for _, tag := range []string{ "autobuild-false-and-referenced", "autobuild-false-and-not-referenced", } { - Expect(stdout).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:%s", tag)) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:%s", tag)) } }) By("not applying referenced Image components with deployByDefault unset", func() { - Expect(stdout).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:autobuild-not-set-and-referenced")) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:autobuild-not-set-and-referenced")) }) }) }) When("running odo dev with some components referenced in the Devfile", func() { var devSession helper.DevSession - var stdout, stderr string BeforeEach(func() { - var bOut, bErr []byte var err error //TODO (rm3l): we do not support passing a custom debug command yet. That's why we are manually updating the Devfile to change the default debug command. helper.UpdateDevfileContent(filepath.Join(commonVar.Context, "devfile.yaml"), []helper.DevfileUpdater{ @@ -627,14 +613,12 @@ var _ = Describe("odo dev debug command tests", func() { if podman { args = append(args, "--forward-localhost") } - devSession, bOut, bErr, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: args, EnvVars: envvars, RunOnPodman: podman, }) Expect(err).ShouldNot(HaveOccurred()) - stdout = string(bOut) - stderr = string(bErr) }) AfterEach(func() { @@ -646,7 +630,7 @@ var _ = Describe("odo dev debug command tests", func() { It("should create the appropriate resources", func() { if podman { - k8sOcComponents := helper.ExtractK8sAndOcComponentsFromOutputOnPodman(stderr) + k8sOcComponents := helper.ExtractK8sAndOcComponentsFromOutputOnPodman(devSession.ErrOut) By("handling Kubernetes/OpenShift components to create automatically", func() { Expect(k8sOcComponents).Should(ContainElements( "k8s-deploybydefault-true-and-referenced", @@ -685,7 +669,7 @@ var _ = Describe("odo dev debug command tests", func() { "ocp-deploybydefault-false-and-referenced", "ocp-deploybydefault-not-set-and-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) @@ -696,7 +680,7 @@ var _ = Describe("odo dev debug command tests", func() { "ocp-deploybydefault-true-and-referenced", "ocp-deploybydefault-true-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) By("automatically applying non-referenced Kubernetes/OpenShift components with deployByDefault not set", func() { @@ -704,7 +688,7 @@ var _ = Describe("odo dev debug command tests", func() { "k8s-deploybydefault-not-set-and-not-referenced", "ocp-deploybydefault-not-set-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) @@ -713,7 +697,7 @@ var _ = Describe("odo dev debug command tests", func() { "k8s-deploybydefault-false-and-not-referenced", "ocp-deploybydefault-false-and-not-referenced", } { - Expect(stdout).ShouldNot(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("Creating resource Pod/%s", l)) } }) } @@ -729,7 +713,7 @@ var _ = Describe("odo dev debug command tests", func() { "autobuild-false-and-referenced", "autobuild-not-set-and-referenced", } { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) } }) By("automatically applying image components with autoBuild=true", func() { @@ -737,14 +721,14 @@ var _ = Describe("odo dev debug command tests", func() { "autobuild-true-and-referenced", "autobuild-true-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) } }) By("automatically applying non-referenced Image components with autoBuild not set", func() { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:autobuild-not-set-and-not-referenced", imageMessagePrefix)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:autobuild-not-set-and-not-referenced", imageMessagePrefix)) }) By("not applying non-referenced image components with autoBuild=false", func() { - Expect(stdout).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:autobuild-false-and-not-referenced")) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:autobuild-false-and-not-referenced")) }) }) }) diff --git a/tests/integration/cmd_dev_test.go b/tests/integration/cmd_dev_test.go index cf6d9c09f60..ba0290d3709 100644 --- a/tests/integration/cmd_dev_test.go +++ b/tests/integration/cmd_dev_test.go @@ -106,8 +106,7 @@ echo "$@" Expect(err).ShouldNot(HaveOccurred()) var devSession helper.DevSession - var stderrBytes []byte - devSession, _, stderrBytes, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: false, CmdlineArgs: []string{"-v", "3"}, EnvVars: []string{ @@ -121,7 +120,7 @@ echo "$@" devSession.WaitEnd() }() - Expect(string(stderrBytes)).Should(MatchRegexp("timeout \\([^()]+\\) while waiting for Podman version")) + Expect(devSession.ErrOut).Should(MatchRegexp("timeout \\([^()]+\\) while waiting for Podman version")) }) When("using a default namespace", func() { @@ -138,19 +137,19 @@ echo "$@" } // Resources might not pass the security requirements on the default namespace on certain clusters (case of OpenShift 4.14), // but this is not important here, as we just want to make sure that the warning message is displayed (even if the Dev Session does not start correctly). - devSession, _, stderr, err := helper.WaitForDevModeToContain(helper.DevSessionOpts{}, "Running on the cluster in Dev mode", false, false) + devSession, err := helper.WaitForDevModeToContain(helper.DevSessionOpts{}, "Running on the cluster in Dev mode", false, false) Expect(err).ShouldNot(HaveOccurred()) defer func() { devSession.Stop() devSession.WaitEnd() }() - Expect(string(stderr)).To(ContainSubstring(fmt.Sprintf("You are using \"default\" %[1]s, odo may not work as expected in the default %[1]s.", namespace))) + Expect(devSession.ErrOut).To(ContainSubstring(fmt.Sprintf("You are using \"default\" %[1]s, odo may not work as expected in the default %[1]s.", namespace))) }) }) It("should add annotation to use ImageStreams", func() { // #6376 - err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents []byte, ports map[string]string) { + err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents string, ports map[string]string) { annotations := commonVar.CliRunner.GetAnnotationsDeployment(cmpName, "app", commonVar.Project) Expect(annotations["alpha.image.policy.openshift.io/resolve-names"]).To(Equal("*")) }) @@ -158,7 +157,7 @@ echo "$@" }) It("should show validation errors if the devfile is incorrect", func() { - err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents []byte, ports map[string]string) { + err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents string, ports map[string]string) { helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "kind: run", "kind: build") helper.WaitForOutputToContain("Error occurred on Push", 180, 10, session) }) @@ -173,7 +172,7 @@ echo "$@" // watch that project err := helper.RunDevMode(helper.DevSessionOpts{ RunOnPodman: podman, - }, func(session *gexec.Session, outContents, errContents []byte, ports map[string]string) { + }, func(session *gexec.Session, outContents, errContents string, ports map[string]string) { // Change some other file B helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "App started", "App is super started") @@ -215,8 +214,6 @@ echo "$@" debug := debug When(fmt.Sprintf("running with --no-commands (debug=%v)", debug), helper.LabelPodmanIf(podman, func() { var devSession helper.DevSession - var stdout, stderr string - var ports map[string]string BeforeEach(func() { args := []string{"--no-commands"} if debug { @@ -227,12 +224,9 @@ echo "$@" CmdlineArgs: args, } - var outB, errB []byte var err error - devSession, outB, errB, ports, err = helper.StartDevMode(opts) + devSession, err = helper.StartDevMode(opts) Expect(err).ShouldNot(HaveOccurred()) - stdout = string(outB) - stderr = string(errB) }) AfterEach(func() { @@ -243,19 +237,19 @@ echo "$@" It("should start the dev session", func() { By("not executing the build command", func() { - for _, out := range []string{stdout, stderr} { + for _, out := range []string{devSession.StdOut, devSession.ErrOut} { Expect(out).ShouldNot(ContainSubstring("Building your application in container on cluster")) } }) By("not executing the run command", func() { - for _, out := range []string{stdout, stderr} { + for _, out := range []string{devSession.StdOut, devSession.ErrOut} { Expect(out).ShouldNot(ContainSubstring("Executing the application")) } }) By("syncing the files", func() { - Expect(stdout).Should(ContainSubstring("Syncing files into the container")) + Expect(devSession.StdOut).Should(ContainSubstring("Syncing files into the container")) component := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) execResult, _ := component.Exec("runtime", []string{"ls", "-lai", "/projects"}, pointer.Bool(true)) @@ -268,9 +262,9 @@ echo "$@" }) By("setting up port forwarding", func() { - Expect(ports).ShouldNot(BeEmpty()) - _, ok := ports["3000"] - Expect(ok).To(BeTrue(), fmt.Sprintf("missing port forwarded for 3000: %v", ports)) + Expect(devSession.Endpoints).ShouldNot(BeEmpty()) + _, ok := devSession.Endpoints["3000"] + Expect(ok).To(BeTrue(), fmt.Sprintf("missing port forwarded for 3000: %v", devSession.Endpoints)) }) }) })) @@ -278,7 +272,7 @@ echo "$@" } It("ensure that index information is updated", func() { - err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents []byte, ports map[string]string) { + err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents string, ports map[string]string) { indexAfterPush, err := util.ReadFileIndex(filepath.Join(commonVar.Context, ".odo", "odo-file-index.json")) Expect(err).ToNot(HaveOccurred()) @@ -368,7 +362,7 @@ echo "$@" if os.Getenv("KUBERNETES") != "true" { Skip("This is a Kubernetes specific scenario, skipping") } - err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents []byte, ports map[string]string) { + err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents string, ports map[string]string) { component := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) podDef := component.GetPodDef() Expect(podDef.Spec.SecurityContext.RunAsNonRoot).To(BeNil()) @@ -390,7 +384,7 @@ echo "$@" if os.Getenv("KUBERNETES") != "true" { Skip("This is a Kubernetes specific scenario, skipping") } - err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents []byte, ports map[string]string) { + err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents string, ports map[string]string) { component := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) podDef := component.GetPodDef() Expect(*podDef.Spec.SecurityContext.RunAsNonRoot).To(BeTrue()) @@ -421,11 +415,11 @@ echo "$@" When("recording telemetry data", helper.LabelPodmanIf(podman, func() { BeforeEach(func() { helper.EnableTelemetryDebug() - session, _, _, _, _ := helper.StartDevMode(helper.DevSessionOpts{ + devSession, _ := helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) AfterEach(func() { helper.ResetTelemetry() @@ -470,7 +464,7 @@ echo "$@" BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -508,7 +502,7 @@ ComponentSettings: BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) @@ -536,7 +530,7 @@ ComponentSettings: } helper.Cmd("odo", "preference", "set", "-f", "Ephemeral", "false").ShouldPass() var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) @@ -595,7 +589,7 @@ ComponentSettings: } helper.Cmd("odo", "preference", "set", "-f", "Ephemeral", "false").ShouldPass() var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) @@ -658,7 +652,7 @@ ComponentSettings: if noCommandsFlag != "" { args = append(args, noCommandsFlag) } - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: args, RunOnPodman: podman, }) @@ -695,7 +689,7 @@ ComponentSettings: }) It("should trigger a push", func() { - _, _, _, err := devSession.WaitSync() + err := devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) component := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) execResult, _ := component.Exec("runtime", []string{"cat", "/projects/server.js"}, pointer.Bool(true)) @@ -710,7 +704,6 @@ ComponentSettings: When("a delay is necessary for the component to start and running odo dev", func() { var devSession helper.DevSession - var ports map[string]string BeforeEach(func() { helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), @@ -721,7 +714,7 @@ ComponentSettings: "sleep 80 ; npm start") var err error - devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) @@ -731,7 +724,7 @@ ComponentSettings: }) It("should first fail then succeed querying endpoint", func() { - url := fmt.Sprintf("http://%s", ports["3000"]) + url := fmt.Sprintf("http://%s", devSession.Endpoints["3000"]) _, err := http.Get(url) Expect(err).To(HaveOccurred()) @@ -742,9 +735,9 @@ ComponentSettings: }, 180, 10).Should(Equal(true)) // Get new random port after restart - _, _, ports, err = devSession.GetInfo() + err = devSession.UpdateInfo() Expect(err).ToNot(HaveOccurred()) - url = fmt.Sprintf("http://%s", ports["3000"]) + url = fmt.Sprintf("http://%s", devSession.Endpoints["3000"]) resp, err := http.Get(url) Expect(err).ToNot(HaveOccurred()) @@ -765,7 +758,7 @@ ComponentSettings: BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) @@ -926,7 +919,7 @@ ComponentSettings: opts := helper.DevSessionOpts{ RunOnPodman: podman, } - devSession, _, _, err := helper.WaitForDevModeToContain(opts, "Building your application in container", false, false) + devSession, err := helper.WaitForDevModeToContain(opts, "Building your application in container", false, false) Expect(err).ShouldNot(HaveOccurred()) // Build is taking long => it should be cancellable @@ -948,7 +941,7 @@ ComponentSettings: RunOnPodman: podman, } // Run command is launched in the background - devSession, _, _, err := helper.WaitForDevModeToContain(opts, "Waiting for the application to be ready", false, false) + devSession, err := helper.WaitForDevModeToContain(opts, "Waiting for the application to be ready", false, false) Expect(err).ShouldNot(HaveOccurred()) // Build is taking long => it should be cancellable @@ -998,7 +991,7 @@ ComponentSettings: filepath.Join("source", "devfiles", "nodejs", devfile.devfileName), filepath.Join(commonVar.Context, "devfile.yaml"), cmpName) - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ EnvVars: devfile.envvars, }) Expect(err).To(BeNil()) @@ -1010,7 +1003,7 @@ ComponentSettings: helper.ReplaceStrings(filepath.Join(commonVar.Context, "devfile.yaml"), devfile.deploymentName, devfile.newDeploymentName) - _, _, _, err := devSession.WaitSync() + err := devSession.WaitSync() Expect(err).To(BeNil()) }) AfterEach(func() { @@ -1049,7 +1042,6 @@ ComponentSettings: When(ctx.title, func() { var ( devSession helper.DevSession - out []byte err error getDeployArgs = []string{"get", "deployments", "-n", commonVar.Project} ) @@ -1060,7 +1052,7 @@ ComponentSettings: filepath.Join("source", "devfiles", "nodejs", ctx.devfile), filepath.Join(commonVar.Context, "devfile.yaml"), cmpName) - devSession, out, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).To(BeNil()) }) @@ -1071,7 +1063,7 @@ ComponentSettings: It("should have created the necessary k8s resources", func() { By("checking the output for the resources", func() { - helper.MatchAllInOutput(string(out), ctx.matchResources) + helper.MatchAllInOutput(devSession.StdOut, ctx.matchResources) }) By("fetching the resources from the cluster", func() { helper.MatchAllInOutput(string(commonVar.CliRunner.Run(getDeployArgs...).Out.Contents()), ctx.matchResources) @@ -1092,7 +1084,6 @@ ComponentSettings: var ( nodejsProject, goProject string nodejsDevSession, goDevSession helper.DevSession - nodejsPorts, goPorts map[string]string nodejsLocalPort = helper.GetCustomStartPort() goLocalPort = nodejsLocalPort + 1 @@ -1124,7 +1115,7 @@ ComponentSettings: BeforeEach(func() { helper.Chdir(nodejsProject) var err error - nodejsDevSession, _, _, nodejsPorts, err = helper.StartDevMode(helper.DevSessionOpts{ + nodejsDevSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: []string{"--port-forward", fmt.Sprintf("%d:%s", nodejsLocalPort, nodejsContainerPort)}, RunOnPodman: podman, TimeoutInSeconds: 0, @@ -1142,7 +1133,7 @@ ComponentSettings: BeforeEach(func() { helper.Chdir(goProject) var err error - goDevSession, _, _, goPorts, err = helper.StartDevMode(helper.DevSessionOpts{ + goDevSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: []string{"--port-forward", fmt.Sprintf("%d:%s", goLocalPort, goContainerPort)}, RunOnPodman: podman, TimeoutInSeconds: 0, @@ -1157,8 +1148,8 @@ ComponentSettings: helper.Chdir(commonVar.Context) }) It("should be able to run both the sessions", func() { - Expect(nodejsPorts[nodejsContainerPort]).To(BeEquivalentTo(nodejsURL)) - Expect(goPorts[goContainerPort]).To(BeEquivalentTo(goURL)) + Expect(nodejsDevSession.Endpoints[nodejsContainerPort]).To(BeEquivalentTo(nodejsURL)) + Expect(goDevSession.Endpoints[goContainerPort]).To(BeEquivalentTo(goURL)) helper.HttpWaitForWithStatus(fmt.Sprintf("http://%s", nodejsURL), "Hello from Node.js Starter Application!", 1, 0, 200) helper.HttpWaitForWithStatus(fmt.Sprintf("http://%s", goURL), "Hello, !", 1, 0, 200) }) @@ -1168,12 +1159,12 @@ ComponentSettings: wg.Add(2) go func() { defer wg.Done() - _, _, _, err := nodejsDevSession.WaitSync() + err := nodejsDevSession.WaitSync() Expect(err).ToNot(HaveOccurred()) }() go func() { defer wg.Done() - _, _, _, err := goDevSession.WaitSync() + err := goDevSession.WaitSync() Expect(err).ToNot(HaveOccurred()) }() helper.ReplaceString(filepath.Join(goProject, "main.go"), "Hello, %s!", "H3110, %s!") @@ -1181,8 +1172,8 @@ ComponentSettings: wg.Wait() }) It("should be possible to access both the projects on same address and port", func() { - Expect(nodejsPorts[nodejsContainerPort]).To(BeEquivalentTo(nodejsURL)) - Expect(goPorts[goContainerPort]).To(BeEquivalentTo(goURL)) + Expect(nodejsDevSession.Endpoints[nodejsContainerPort]).To(BeEquivalentTo(nodejsURL)) + Expect(goDevSession.Endpoints[goContainerPort]).To(BeEquivalentTo(goURL)) helper.HttpWaitForWithStatus(fmt.Sprintf("http://%s", nodejsURL), "H3110 from Node.js Starter Application!", 1, 0, 200) helper.HttpWaitForWithStatus(fmt.Sprintf("http://%s", goURL), "H3110, !", 1, 0, 200) }) @@ -1207,14 +1198,13 @@ ComponentSettings: When("running odo dev", func() { var devSession helper.DevSession - var ports map[string]string BeforeEach(func() { var err error opts := []string{} if manual { opts = append(opts, "--no-watch") } - devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: opts, RunOnPodman: podman, }) @@ -1227,7 +1217,7 @@ ComponentSettings: }) It(fmt.Sprintf("should have no endpoint forwarded (podman=%v, manual=%v)", podman, manual), func() { - Expect(ports).To(BeEmpty()) + Expect(devSession.Endpoints).To(BeEmpty()) }) }) }) @@ -1258,7 +1248,6 @@ ComponentSettings: When("running odo dev", func() { var devSession helper.DevSession - var ports map[string]string BeforeEach(func() { var err error opts := []string{} @@ -1268,7 +1257,7 @@ ComponentSettings: if manual { opts = append(opts, "--no-watch") } - devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: opts, NoRandomPorts: NoRandomPorts, RunOnPodman: podman, @@ -1284,7 +1273,7 @@ ComponentSettings: }) It(fmt.Sprintf("should expose the endpoint on localhost (podman=%v, manual=%v, customPortForwarding=%v, customAddress=%v)", podman, manual, customPortForwarding, customAddress), func() { - url := fmt.Sprintf("http://%s", ports[containerPort]) + url := fmt.Sprintf("http://%s", devSession.Endpoints[containerPort]) if customPortForwarding { Expect(url).To(ContainSubstring(strconv.Itoa(localPort))) } @@ -1298,8 +1287,6 @@ ComponentSettings: }) When("modifying name for container in Devfile", func() { - var stdout string - var stderr string BeforeEach(func() { if manual { if os.Getenv("SKIP_KEY_PRESS") == "true" { @@ -1307,18 +1294,15 @@ ComponentSettings: } } var ( - wg sync.WaitGroup - err error - stdoutBytes []byte - stderrBytes []byte + wg sync.WaitGroup + err error ) wg.Add(1) go func() { defer wg.Done() - stdoutBytes, stderrBytes, ports, err = devSession.WaitSync() + err = devSession.WaitSync() Expect(err).Should(Succeed()) - stdout = string(stdoutBytes) - stderr = string(stderrBytes) + }() src := "runtime" dst := "other" @@ -1332,8 +1316,8 @@ ComponentSettings: It(fmt.Sprintf("should react on the Devfile modification (podman=%v, manual=%v, customPortForwarding=%v, customAddress=%v)", podman, manual, customPortForwarding, customAddress), func() { By("not warning users that odo dev needs to be restarted", func() { warning := "Please restart 'odo dev'" - Expect(stdout).ShouldNot(ContainSubstring(warning)) - Expect(stderr).ShouldNot(ContainSubstring(warning)) + Expect(devSession.StdOut).ShouldNot(ContainSubstring(warning)) + Expect(devSession.ErrOut).ShouldNot(ContainSubstring(warning)) }) By("updating the pod", func() { component := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) @@ -1344,7 +1328,7 @@ ComponentSettings: By("exposing the endpoint", func() { Eventually(func(g Gomega) { - url := fmt.Sprintf("http://%s", ports[containerPort]) + url := fmt.Sprintf("http://%s", devSession.Endpoints[containerPort]) if customPortForwarding { Expect(url).To(ContainSubstring(strconv.Itoa(localPort))) } @@ -1390,7 +1374,6 @@ ComponentSettings: When("running odo dev", func() { var devSession helper.DevSession - var ports map[string]string BeforeEach(func() { opts := []string{} if customPortForwarding { @@ -1400,7 +1383,7 @@ ComponentSettings: opts = append(opts, "--no-watch") } var err error - devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: opts, NoRandomPorts: NoRandomPorts, RunOnPodman: podman, @@ -1417,13 +1400,13 @@ ComponentSettings: It(fmt.Sprintf("should expose all endpoints on localhost regardless of exposure(podman=%v, manual=%v, customPortForwarding=%v, customAddress=%v)", podman, manual, customPortForwarding, customAddress), func() { By("not exposing debug endpoints", func() { for _, p := range []int{5005, 5006} { - _, found := ports[strconv.Itoa(p)] + _, found := devSession.Endpoints[strconv.Itoa(p)] Expect(found).To(BeFalse(), fmt.Sprintf("debug port %d should not be forwarded", p)) } }) getServerResponse := func(containerPort, localPort string) (string, error) { - url := fmt.Sprintf("http://%s", ports[containerPort]) + url := fmt.Sprintf("http://%s", devSession.Endpoints[containerPort]) if customPortForwarding { Expect(url).To(ContainSubstring(localPort)) } @@ -1462,15 +1445,13 @@ ComponentSettings: devSession.PressKey('p') } - var stdout, stderr []byte - var err error - stdout, stderr, _, err = devSession.WaitSync() + err := devSession.WaitSync() Expect(err).Should(Succeed()) By("not warning users that odo dev needs to be restarted because the Devfile has not changed", func() { warning := "Please restart 'odo dev'" - Expect(stdout).ShouldNot(ContainSubstring(warning)) - Expect(stderr).ShouldNot(ContainSubstring(warning)) + Expect(devSession.StdOut).ShouldNot(ContainSubstring(warning)) + Expect(devSession.ErrOut).ShouldNot(ContainSubstring(warning)) }) for i := range containerPorts { @@ -1529,17 +1510,17 @@ ComponentSettings: }) When("doing odo dev", func() { - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("3. should check if the env variable has a correct value", func() { @@ -1551,18 +1532,18 @@ ComponentSettings: }) When("doing odo dev with --var flag", func() { - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: []string{"--var", "VALUE_TEST=baz"}, RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should check if the env variable has a correct value", func() { @@ -1574,21 +1555,21 @@ ComponentSettings: }) When("doing odo dev with --var-file flag", func() { - var session helper.DevSession + var devSession helper.DevSession varfilename := "vars.txt" BeforeEach(func() { var err error err = helper.CreateFileWithContent(varfilename, "VALUE_TEST=baz") Expect(err).ToNot(HaveOccurred()) - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: []string{"--var-file", "vars.txt"}, RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() helper.DeleteFile(varfilename) }) @@ -1601,22 +1582,22 @@ ComponentSettings: }) When("doing odo dev with --var-file flag and setting value in env", func() { - var session helper.DevSession + var devSession helper.DevSession varfilename := "vars.txt" BeforeEach(func() { var err error _ = os.Setenv("VALUE_TEST", "baz") err = helper.CreateFileWithContent(varfilename, "VALUE_TEST") Expect(err).ToNot(HaveOccurred()) - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: []string{"--var-file", "vars.txt"}, RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() helper.DeleteFile(varfilename) _ = os.Unsetenv("VALUE_TEST") }) @@ -1647,7 +1628,7 @@ ComponentSettings: It("should be able to exec command", func() { err := helper.RunDevMode(helper.DevSessionOpts{ RunOnPodman: podman, - }, func(session *gexec.Session, out, err []byte, ports map[string]string) { + }, func(session *gexec.Session, out, err string, ports map[string]string) { component := helper.NewComponent(devfileCmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) output, _ := component.Exec("runtime", []string{"ls", "-lai", "/projects"}, pointer.Bool(true)) helper.MatchAllInOutput(output, []string{"test_env_variable", "test_build_env_variable"}) @@ -1673,7 +1654,7 @@ ComponentSettings: It("should be able to exec command", func() { err := helper.RunDevMode(helper.DevSessionOpts{ RunOnPodman: podman, - }, func(session *gexec.Session, out, err []byte, ports map[string]string) { + }, func(session *gexec.Session, out, err string, ports map[string]string) { component := helper.NewComponent(devfileCmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) output, _ := component.Exec("runtime", []string{"ls", "-lai", "/projects"}, pointer.Bool(true)) helper.MatchAllInOutput(output, []string{"test_build_env_variable1", "test_build_env_variable2", "test_env_variable1", "test_env_variable2"}) @@ -1699,7 +1680,7 @@ ComponentSettings: It("should be able to exec command", func() { err := helper.RunDevMode(helper.DevSessionOpts{ RunOnPodman: podman, - }, func(session *gexec.Session, out, err []byte, ports map[string]string) { + }, func(session *gexec.Session, out, err string, ports map[string]string) { component := helper.NewComponent(devfileCmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) output, _ := component.Exec("runtime", []string{"ls", "-lai", "/projects"}, pointer.Bool(true)) helper.MatchAllInOutput(output, []string{"build env variable with space", "env with space"}) @@ -1711,7 +1692,7 @@ ComponentSettings: When("creating local files and dir and running odo dev - "+devfileHandlerCtx.name, func() { var newDirPath, newFilePath, stdOut, podName string - var session helper.DevSession + var devSession helper.DevSession var devfileCmpName string BeforeEach(func() { devfileCmpName = helper.RandString(6) @@ -1732,13 +1713,13 @@ ComponentSettings: // Create a new directory helper.MakeDir(newDirPath) var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should correctly propagate changes to the container", func() { @@ -1755,7 +1736,7 @@ ComponentSettings: // Now we delete the file and dir and push helper.DeleteDir(newFilePath) helper.DeleteDir(newDirPath) - _, _, _, err := session.WaitSync() + err := devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) }) It("should not list deleted dir and file in container", func() { @@ -1783,7 +1764,7 @@ ComponentSettings: When("creating local files and dir and running odo dev - "+devfileHandlerCtx.name, func() { var newDirPath, newFilePath, stdOut, podName string - var session helper.DevSession + var devSession helper.DevSession var devfileCmpName string BeforeEach(func() { devfileCmpName = helper.RandString(6) @@ -1804,13 +1785,13 @@ ComponentSettings: // Create a new directory helper.MakeDir(newDirPath) var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should correctly propagate changes to the container", func() { @@ -1827,7 +1808,7 @@ ComponentSettings: // Now we delete the file and dir and push helper.DeleteDir(newFilePath) helper.DeleteDir(newDirPath) - _, _, _, err := session.WaitSync() + err := devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) }) It("should not list deleted dir and file in container", func() { @@ -1842,7 +1823,7 @@ ComponentSettings: When("adding local files to gitignore and running odo dev", func() { var gitignorePath, newDirPath, newFilePath1, newFilePath2, newFilePath3, newFilePath4, newFilePath5, stdOut, podName string - var session helper.DevSession + var devSession helper.DevSession var devfileCmpName string BeforeEach(func() { devfileCmpName = helper.RandString(6) @@ -1884,12 +1865,12 @@ ComponentSettings: fmt.Printf("the .gitignore file was not created, reason %v", err.Error()) } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) checkSyncedFiles := func(podName string) { @@ -1914,7 +1895,7 @@ ComponentSettings: }) It("should synchronize it only", func() { - _, _, _, _ = session.WaitSync() + _ = devSession.WaitSync() podName = commonVar.CliRunner.GetRunningPodNameByComponent(devfileCmpName, commonVar.Project) checkSyncedFiles(podName) }) @@ -1926,7 +1907,7 @@ ComponentSettings: }) It("should not synchronize it", func() { - session.CheckNotSynced(10 * time.Second) + devSession.CheckNotSynced(10 * time.Second) }) }) @@ -1936,14 +1917,14 @@ ComponentSettings: }) It("should not synchronize it", func() { - session.CheckNotSynced(10 * time.Second) + devSession.CheckNotSynced(10 * time.Second) }) }) }) When("devfile has sourcemappings and running odo dev - "+devfileHandlerCtx.name, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) @@ -1955,13 +1936,13 @@ ComponentSettings: devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should sync files to the correct location", func() { @@ -1984,7 +1965,7 @@ ComponentSettings: When("project and clonePath is present in devfile and running odo dev - "+devfileHandlerCtx.name, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) @@ -1998,12 +1979,12 @@ ComponentSettings: } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should sync to the correct dir in container", func() { @@ -2022,7 +2003,7 @@ ComponentSettings: When("devfile project field is present and running odo dev - "+devfileHandlerCtx.name, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) @@ -2037,12 +2018,12 @@ ComponentSettings: // reset clonePath and change the workdir accordingly, it should sync to project name helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "clonePath: webapp/", "# clonePath: webapp/") var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should sync to the correct dir in container", func() { @@ -2057,7 +2038,7 @@ ComponentSettings: When("multiple projects are present - "+devfileHandlerCtx.name, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) @@ -2070,12 +2051,12 @@ ComponentSettings: } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should sync to the correct dir in container", func() { @@ -2092,7 +2073,7 @@ ComponentSettings: When("no project is present - "+devfileHandlerCtx.name, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) @@ -2104,12 +2085,12 @@ ComponentSettings: devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should sync to the correct dir in container", func() { @@ -2125,7 +2106,7 @@ ComponentSettings: When("running odo dev with devfile contain volume - "+devfileHandlerCtx.name, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) @@ -2137,12 +2118,12 @@ ComponentSettings: devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should create pvc and reuse if it shares the same devfile volume name", func() { @@ -2200,7 +2181,7 @@ ComponentSettings: When("running odo dev with devfile containing volume-component - "+devfileHandlerCtx.name, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { if os.Getenv("KUBERNETES") == "true" { Skip("This is a OpenShift specific scenario, skipping") @@ -2215,15 +2196,15 @@ ComponentSettings: devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { if os.Getenv("KUBERNETES") == "true" { return } - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should successfully use the volume components in container components", func() { @@ -2247,11 +2228,10 @@ ComponentSettings: openshiftDeploymentName = "my-openshift-component" DEVFILEPORT = "8080" ) - var session helper.DevSession - var sessionOut, sessionErr []byte - var err error - var ports map[string]string - + var ( + devSession helper.DevSession + err error + ) BeforeEach(func() { helper.CopyExampleDevFile( filepath.Join("source", "devfiles", "nodejs", "devfile-composite-apply-commands.yaml"), @@ -2329,7 +2309,7 @@ ComponentSettings: // Increasing verbosity to check that extra args are being passed to the "podman" commands cmdLineArgs = append(cmdLineArgs, "-v=4") } - session, sessionOut, sessionErr, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, EnvVars: env, CmdlineArgs: cmdLineArgs, @@ -2358,14 +2338,14 @@ ComponentSettings: filepath.Join(commonVar.Context, "Dockerfile"), commonVar.Context) if podman { - Expect(string(sessionErr)).To(ContainSubstring(substring)) + Expect(devSession.ErrOut).To(ContainSubstring(substring)) } else { - Expect(string(sessionOut)).To(ContainSubstring(substring)) - Expect(string(sessionOut)).To(ContainSubstring("push quay.io/unknown-account/myimage")) + Expect(devSession.StdOut).To(ContainSubstring(substring)) + Expect(devSession.StdOut).To(ContainSubstring("push quay.io/unknown-account/myimage")) } } checkEndpointAccessible := func(message []string) { - url := fmt.Sprintf("http://%s", ports[DEVFILEPORT]) + url := fmt.Sprintf("http://%s", devSession.Endpoints[DEVFILEPORT]) resp, e := http.Get(url) Expect(e).ToNot(HaveOccurred()) defer resp.Body.Close() @@ -2388,7 +2368,7 @@ ComponentSettings: } expected += "-" By("checking that extra args are passed to the podman play kube command", func() { - Expect(string(sessionErr)).Should(ContainSubstring(expected)) + Expect(devSession.ErrOut).Should(ContainSubstring(expected)) }) } @@ -2401,14 +2381,14 @@ ComponentSettings: checkDeploymentsExist() }) By("ensuring multiple deployments exist for selector error is not occurred", func() { - Expect(string(sessionErr)).ToNot(ContainSubstring("multiple Deployments exist for the selector")) + Expect(devSession.ErrOut).ToNot(ContainSubstring("multiple Deployments exist for the selector")) }) } By("checking odo dev watches correctly", func() { // making changes to the project again helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "world from node.js", "from the new Node.js Starter Application") - _, _, _, err = session.WaitSync() + err = devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) if !podman { checkDeploymentsExist() @@ -2418,8 +2398,8 @@ ComponentSettings: }) By("cleaning up the resources on ending the session", func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() if !podman { out := commonVar.CliRunner.Run("get", "deployments").Out.Contents() Expect(string(out)).ToNot(ContainSubstring(k8sDeploymentName)) @@ -2463,23 +2443,23 @@ CMD ["npm", "start"] url = server.URL helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "./Dockerfile", url) - session, sessionOut, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ EnvVars: env, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() server.Close() }) It("should build and push image when odo dev is run", func() { - lines, _ := helper.ExtractLines(string(sessionOut)) + lines, _ := helper.ExtractLines(devSession.StdOut) _, ok := helper.FindFirstElementIndexMatchingRegExp(lines, buildRegexp) Expect(ok).To(BeTrue(), "build regexp not found in output: "+buildRegexp) - Expect(string(sessionOut)).To(ContainSubstring("push quay.io/unknown-account/myimage")) + Expect(devSession.StdOut).To(ContainSubstring("push quay.io/unknown-account/myimage")) }) }) When(fmt.Sprintf("%v remote server returns an error when odo dev is run", env), func() { @@ -2499,7 +2479,7 @@ CMD ["npm", "start"] }) It("should not build images when odo dev is run", func() { - _, sessionOut, _, err := helper.WaitForDevModeToContain( + devSession, err := helper.WaitForDevModeToContain( helper.DevSessionOpts{ EnvVars: env, }, @@ -2507,8 +2487,8 @@ CMD ["npm", "start"] true, false) Expect(err).To(BeNil()) - Expect(sessionOut).NotTo(ContainSubstring("build -t quay.io/unknown-account/myimage -f ")) - Expect(sessionOut).NotTo(ContainSubstring("push quay.io/unknown-account/myimage")) + Expect(devSession.StdOut).NotTo(ContainSubstring("build -t quay.io/unknown-account/myimage -f ")) + Expect(devSession.StdOut).NotTo(ContainSubstring("push quay.io/unknown-account/myimage")) }) }) } @@ -2537,7 +2517,7 @@ CMD ["npm", "start"] When("running odo dev and devfile with composite command - "+devfileHandlerCtx.name, helper.LabelPodmanIf(podman, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) @@ -2549,14 +2529,14 @@ CMD ["npm", "start"] devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should execute all commands in composite command", func() { @@ -2570,7 +2550,7 @@ CMD ["npm", "start"] When("running odo dev and composite command is marked as parallel:true - "+devfileHandlerCtx.name, helper.LabelPodmanIf(podman, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) @@ -2582,13 +2562,13 @@ CMD ["npm", "start"] devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should execute all commands in composite command", func() { @@ -2602,7 +2582,7 @@ CMD ["npm", "start"] When("running odo dev and composite command are nested - "+devfileHandlerCtx.name, helper.LabelPodmanIf(podman, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = helper.RandString(6) helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) @@ -2614,13 +2594,13 @@ CMD ["npm", "start"] devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should execute all commands in composite commmand", func() { @@ -2634,9 +2614,7 @@ CMD ["npm", "start"] })) When("running odo dev and composite command is used as a run command - "+devfileHandlerCtx.name, helper.LabelPodmanIf(podman, func() { - var session helper.DevSession - var stdout []byte - var stderr []byte + var devSession helper.DevSession var devfileCmpName string BeforeEach(func() { devfileCmpName = helper.RandString(6) @@ -2649,23 +2627,23 @@ CMD ["npm", "start"] devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } var err error - session, stdout, stderr, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should run successfully", func() { By("telling the user that odo is synchronizing the files", func() { - Expect(string(stdout)).Should(ContainSubstring("Syncing files into the container")) + Expect(string(devSession.StdOut)).Should(ContainSubstring("Syncing files into the container")) }) By("verifying from the output that all commands have been executed", func() { - helper.MatchAllInOutput(string(stdout), []string{ + helper.MatchAllInOutput(devSession.StdOut, []string{ "Building your application in container", "Executing the application (command: mkdir)", "Executing the application (command: echo)", @@ -2675,17 +2653,17 @@ CMD ["npm", "start"] }) By("verifying that any command that did not succeed in the middle has logged such information correctly", func() { - helper.MatchAllInOutput(string(stderr), []string{ + helper.MatchAllInOutput(devSession.ErrOut, []string{ "Devfile command \"echo\" exited with an error status", "intentional-error-message", }) }) By("building the application only once", func() { - // Because of the Spinner, the "Building your application in container" is printed twice in the captured stdout. + // Because of the Spinner, the "Building your application in container" is printed twice in the captured devSession.StdOut. // The bracket allows to match the last occurrence with the command execution timing information. - Expect(strings.Count(string(stdout), "Building your application in container (command: install) [")). - To(BeNumerically("==", 1), "\nOUTPUT: "+string(stdout)+"\n") + Expect(strings.Count(devSession.StdOut, "Building your application in container (command: install) [")). + To(BeNumerically("==", 1), "\nOUTPUT: "+devSession.StdOut+"\n") }) By("verifying that the command did run successfully", func() { @@ -2699,9 +2677,7 @@ CMD ["npm", "start"] // This test does not pass on podman. There are flaky permissions issues on source volume mounted by both components sleeper-run and runtime When("running build and run commands as composite in different containers and a shared volume - "+devfileHandlerCtx.name, helper.LabelPodmanIf(podman, func() { - var session helper.DevSession - var stdout []byte - var stderr []byte + var devSession helper.DevSession var devfileCmpName string BeforeEach(func() { devfileCmpName = helper.RandString(6) @@ -2714,20 +2690,20 @@ CMD ["npm", "start"] devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } var err error - session, stdout, stderr, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should run successfully", func() { By("verifying from the output that all commands have been executed", func() { - helper.MatchAllInOutput(string(stdout), []string{ + helper.MatchAllInOutput(devSession.StdOut, []string{ "Building your application in container (command: mkdir)", "Building your application in container (command: sleep-cmd-build)", "Building your application in container (command: build-cmd)", @@ -2739,19 +2715,19 @@ CMD ["npm", "start"] }) By("verifying that any command that did not succeed in the middle has logged such information correctly", func() { - helper.MatchAllInOutput(string(stderr), []string{ + helper.MatchAllInOutput(devSession.ErrOut, []string{ "Devfile command \"echo-with-error\" exited with an error status", "intentional-error-message", }) }) By("building the application only once per exec command in the build command", func() { - // Because of the Spinner, the "Building your application in container" is printed twice in the captured stdout. + // Because of the Spinner, the "Building your application in container" is printed twice in the captured devSession.StdOut. // The bracket allows to match the last occurrence with the command execution timing information. - out := string(stdout) + out := devSession.StdOut for _, cmd := range []string{"mkdir", "sleep-cmd-build", "build-cmd"} { Expect(strings.Count(out, fmt.Sprintf("Building your application in container (command: %s) [", cmd))). - To(BeNumerically("==", 1), "\nOUTPUT: "+string(stdout)+"\n") + To(BeNumerically("==", 1), "\nOUTPUT: "+devSession.StdOut+"\n") } }) @@ -2793,8 +2769,7 @@ CMD ["npm", "start"] for _, podman := range []bool{false, true} { podman := podman When("running odo dev and run command throws an error", helper.LabelPodmanIf(podman, func() { - var session helper.DevSession - var initErr []byte + var devSession helper.DevSession BeforeEach(func() { helper.CopyExampleDevFile( filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), @@ -2802,18 +2777,18 @@ CMD ["npm", "start"] cmpName) helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "npm start", "npm starts") var err error - session, _, initErr, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should error out with some log", func() { - helper.MatchAllInOutput(string(initErr), []string{ + helper.MatchAllInOutput(devSession.ErrOut, []string{ "exited with an error status in", "Did you mean one of these?", }) @@ -2831,8 +2806,7 @@ CMD ["npm", "start"] } title := fmt.Sprintf("running odo dev%s and build command throws an error", noWatchFlag) When(title, helper.LabelPodmanIf(podman, func() { - var session helper.DevSession - var stdout, stderr []byte + var devSession helper.DevSession BeforeEach(func() { helper.CopyExampleDevFile( filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), @@ -2841,7 +2815,7 @@ CMD ["npm", "start"] helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "npm install", "npm install-does-not-exist") var err error - session, stdout, stderr, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, NoWatch: noWatch, }) @@ -2849,15 +2823,15 @@ CMD ["npm", "start"] }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should error out with some log", func() { - helper.MatchAllInOutput(string(stdout), []string{ + helper.MatchAllInOutput(devSession.StdOut, []string{ "unable to exec command", }) - helper.MatchAllInOutput(string(stderr), []string{ + helper.MatchAllInOutput(devSession.ErrOut, []string{ "Usage: npm ", "Did you mean one of these?", }) @@ -2870,20 +2844,20 @@ CMD ["npm", "start"] podman := podman When("Create and dev java-springboot component", helper.LabelPodmanIf(podman, func() { var devfileCmpName string - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { devfileCmpName = "javaspringboot-" + helper.RandString(6) helper.Cmd("odo", "init", "--name", devfileCmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "springboot", "devfile.yaml")).ShouldPass() helper.CopyExample(filepath.Join("source", "devfiles", "springboot", "project"), commonVar.Context) var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should execute default build and run commands correctly", func() { @@ -2925,7 +2899,7 @@ CMD ["npm", "start"] helper.LabelPodmanIf(podman, func() { err := helper.RunDevMode(helper.DevSessionOpts{ RunOnPodman: podman, - }, func(session *gexec.Session, outContents []byte, errContents []byte, ports map[string]string) { + }, func(session *gexec.Session, outContents string, errContents string, ports map[string]string) { component := helper.NewComponent(devfileCmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) annotations := component.GetAnnotations() var valueFound bool @@ -2975,9 +2949,9 @@ CMD ["npm", "start"] err := helper.RunDevMode(helper.DevSessionOpts{ CmdlineArgs: tt.devAdditionalOpts, RunOnPodman: podman, - }, func(session *gexec.Session, outContents []byte, errContents []byte, ports map[string]string) { - stdout := string(outContents) - stderr := string(errContents) + }, func(session *gexec.Session, outContents string, errContents string, ports map[string]string) { + stdout := outContents + stderr := errContents By("checking the output of the command", func() { helper.MatchAllInOutput(stdout, []string{ @@ -3038,32 +3012,32 @@ CMD ["npm", "start"] It("should error out on an invalid command", func() { By("calling with an invalid build command", func() { - session, stdout, _, _, err := helper.StartDevMode(helper.DevSessionOpts{ + devSession, err := helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, CmdlineArgs: []string{"--build-command", "build-command-does-not-exist"}, }) Expect(err).ToNot(HaveOccurred()) defer func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }() - Expect(string(stdout)).To(ContainSubstring("no build command with name \"build-command-does-not-exist\" found in Devfile")) + Expect(string(devSession.StdOut)).To(ContainSubstring("no build command with name \"build-command-does-not-exist\" found in Devfile")) }) By("calling with a command of another kind (not build)", func() { // devrun is a valid run command, not a build command - session, stdout, _, _, err := helper.StartDevMode(helper.DevSessionOpts{ + devSession, err := helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, CmdlineArgs: []string{"--build-command", "devrun"}, }) Expect(err).ToNot(HaveOccurred()) defer func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }() - Expect(string(stdout)).To(ContainSubstring("no build command with name \"devrun\" found in Devfile")) + Expect(string(devSession.StdOut)).To(ContainSubstring("no build command with name \"devrun\" found in Devfile")) }) }) @@ -3107,32 +3081,32 @@ CMD ["npm", "start"] It("should error out on an invalid command", func() { By("calling with an invalid run command", func() { - session, stdout, _, _, err := helper.StartDevMode(helper.DevSessionOpts{ + devSession, err := helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, CmdlineArgs: []string{"--run-command", "run-command-does-not-exist"}, }) Expect(err).ToNot(HaveOccurred()) defer func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }() - Expect(string(stdout)).To(ContainSubstring("no run command with name \"run-command-does-not-exist\" found in Devfile")) + Expect(string(devSession.StdOut)).To(ContainSubstring("no run command with name \"run-command-does-not-exist\" found in Devfile")) }) By("calling with a command of another kind (not run)", func() { // devbuild is a valid build command, not a run command - session, stdout, _, _, err := helper.StartDevMode(helper.DevSessionOpts{ + devSession, err := helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, CmdlineArgs: []string{"--run-command", "devbuild"}, }) Expect(err).ToNot(HaveOccurred()) defer func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }() - Expect(string(stdout)).To(ContainSubstring("no run command with name \"devbuild\" found in Devfile")) + Expect(string(devSession.StdOut)).To(ContainSubstring("no run command with name \"devbuild\" found in Devfile")) }) }) @@ -3198,30 +3172,29 @@ CMD ["npm", "start"] for _, podman := range []bool{true, false} { podman := podman When("java-springboot application is created and running odo dev", helper.LabelPodmanIf(podman, func() { - var session helper.DevSession + var devSession helper.DevSession var component helper.Component BeforeEach(func() { helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "springboot", "devfile-registry.yaml")).ShouldPass() helper.CopyExample(filepath.Join("source", "devfiles", "springboot", "project"), commonVar.Context) component = helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: []string{"-v", "4"}, RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) When("Update the devfile.yaml", func() { BeforeEach(func() { helper.ReplaceString("devfile.yaml", "memoryLimit: 768Mi", "memoryLimit: 767Mi") - var err error - _, _, _, err = session.WaitSync() + err := devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) }) @@ -3314,21 +3287,21 @@ CMD ["npm", "start"] } } - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { helper.CopyExampleDevFile( filepath.Join("source", "devfiles", "nodejs", "devfile-with-MR-CL-CR.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"), cmpName) var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should check memory Request and Limit", func() { @@ -3343,8 +3316,7 @@ CMD ["npm", "start"] filepath.Join("source", "devfiles", "nodejs", "devfile-with-MR-CL-CR-modified.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"), cmpName) - var err error - _, _, _, err = session.WaitSync() + err := devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) }) @@ -3359,7 +3331,7 @@ CMD ["npm", "start"] for _, podman := range []bool{false, true} { podman := podman When("creating nodejs component, doing odo dev and run command has dev.odo.push.path attribute", helper.LabelPodmanIf(podman, func() { - var session helper.DevSession + var devSession helper.DevSession var devStarted bool BeforeEach(func() { helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", @@ -3372,7 +3344,7 @@ CMD ["npm", "start"] helper.ReplaceString("package.json", "node server.js", "node server/server.js") var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -3380,8 +3352,8 @@ CMD ["npm", "start"] }) AfterEach(func() { if devStarted { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() } }) @@ -3411,7 +3383,7 @@ CMD ["npm", "start"] helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-multiple-endpoints.yaml")).ShouldPass() var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ShouldNot(HaveOccurred()) }) @@ -3471,7 +3443,6 @@ CMD ["npm", "start"] podman := podman When("a container component defines a Command or Args - "+devfileHandlerCtx.name, helper.LabelPodmanIf(podman, func() { var devfileCmpName string - var stdoutBytes, stderrBytes []byte var devSession helper.DevSession var err error @@ -3485,7 +3456,7 @@ CMD ["npm", "start"] if devfileHandlerCtx.sourceHandler != nil { devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName) } - devSession, stdoutBytes, stderrBytes, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ShouldNot(HaveOccurred()) @@ -3498,8 +3469,8 @@ CMD ["npm", "start"] It("should run odo dev successfully (#5620)", func() { const errorMessage = "Failed to create the component:" - Expect(string(stdoutBytes)).ToNot(ContainSubstring(errorMessage)) - Expect(string(stderrBytes)).ToNot(ContainSubstring(errorMessage)) + Expect(devSession.StdOut).ToNot(ContainSubstring(errorMessage)) + Expect(devSession.ErrOut).ToNot(ContainSubstring(errorMessage)) component := helper.NewComponent(devfileCmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) component.Exec("runtime", @@ -3529,7 +3500,7 @@ CMD ["npm", "start"] helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-multiple-endpoints.yaml")).ShouldPass() Expect(helper.VerifyFileExists(".odo/devstate.json")).To(BeFalse()) var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -3561,7 +3532,7 @@ CMD ["npm", "start"] helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-multiple-endpoints.yaml")).ShouldPass() Expect(helper.VerifyFileExists(".odo/devstate.json")).To(BeFalse()) var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -3574,7 +3545,7 @@ CMD ["npm", "start"] }) It("should fail running a second session on the same platform", func() { - _, _, _, err := helper.WaitForDevModeToContain(helper.DevSessionOpts{ + _, err := helper.WaitForDevModeToContain(helper.DevSessionOpts{ RunOnPodman: podman, }, "unable to save state file", true, true) Expect(err).To(HaveOccurred()) @@ -3634,7 +3605,7 @@ CMD ["npm", "start"] cmpName+"-parent") helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -3657,9 +3628,9 @@ CMD ["npm", "start"] It("should update the component", func() { Eventually(func() string { - stdout, _, _, err := devSession.GetInfo() + err := devSession.UpdateInfo() Expect(err).ToNot(HaveOccurred()) - return string(stdout) + return devSession.StdOut }, 180, 10).Should(ContainSubstring("Updating Component")) }) }) @@ -3672,8 +3643,7 @@ CMD ["npm", "start"] ) var customImgName string - var session helper.DevSession - var outContents, errContents []byte + var devSession helper.DevSession BeforeEach(func() { customImgName = fmt.Sprintf("%s:%s", imgName, cmpName) helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) @@ -3684,25 +3654,25 @@ CMD ["npm", "start"] ) helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), imgName, customImgName) var err error - session, outContents, errContents, _, err = helper.StartDevMode( + devSession, err = helper.StartDevMode( helper.DevSessionOpts{RunOnPodman: true, EnvVars: []string{"ODO_PUSH_IMAGES=false"}}, ) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should show warning about being unable to create the resource when running odo dev on podman", func() { - Expect(string(errContents)).To(ContainSubstring("Kubernetes components are not supported on Podman. Skipping: ")) - Expect(string(errContents)).To(ContainSubstring("Apply Kubernetes/Openshift components are not supported on Podman. Skipping: ")) - helper.MatchAllInOutput(string(errContents), []string{"deploy-k8s-resource", "deploy-a-third-k8s-resource"}) + Expect(devSession.ErrOut).To(ContainSubstring("Kubernetes components are not supported on Podman. Skipping: ")) + Expect(devSession.ErrOut).To(ContainSubstring("Apply Kubernetes/Openshift components are not supported on Podman. Skipping: ")) + helper.MatchAllInOutput(devSession.ErrOut, []string{"deploy-k8s-resource", "deploy-a-third-k8s-resource"}) }) It("should build the images when running odo dev on podman", func() { // we do not test push because then it becomes complex to setup image registry credentials to pull the image // all pods created by odo have a `PullAlways` image policy. - Expect(string(outContents)).To(ContainSubstring("Building Image: %s", customImgName)) + Expect(devSession.StdOut).To(ContainSubstring("Building Image: %s", customImgName)) component := helper.NewPodmanComponent(cmpName, "app") Expect(component.ListImages()).To(ContainSubstring(customImgName)) }) @@ -3712,14 +3682,13 @@ CMD ["npm", "start"] podman := podman When("a hotReload capable Run command is used with odo dev", helper.LabelPodmanIf(podman, func() { var devSession helper.DevSession - var stdout []byte var executeRunCommand = "Executing the application (command: dev-run)" var executeBuildCommand = "Building your application" BeforeEach(func() { helper.CopyExample(filepath.Join("source", "java-quarkus"), commonVar.Context) helper.UpdateDevfileContent(filepath.Join(commonVar.Context, "devfile.yaml"), []helper.DevfileUpdater{helper.DevfileMetadataNameSetter(cmpName)}) var err error - devSession, stdout, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -3732,28 +3701,27 @@ CMD ["npm", "start"] }) It("should execute the build and run commands", func() { - Expect(string(stdout)).To(ContainSubstring(executeBuildCommand)) - Expect(string(stdout)).To(ContainSubstring(executeRunCommand)) + Expect(string(devSession.StdOut)).To(ContainSubstring(executeBuildCommand)) + Expect(string(devSession.StdOut)).To(ContainSubstring(executeRunCommand)) By("telling the user that odo is synchronizing the files", func() { - Expect(string(stdout)).Should(ContainSubstring("Syncing files into the container")) + Expect(string(devSession.StdOut)).Should(ContainSubstring("Syncing files into the container")) }) }) When("a source file is modified", func() { BeforeEach(func() { helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "org", "acme", "GreetingResource.java"), "Hello RESTEasy", "Hi RESTEasy") - var err error - stdout, _, _, err = devSession.WaitSync() - Expect(err).Should(Succeed(), stdout) + err := devSession.WaitSync() + Expect(err).Should(Succeed(), devSession.StdOut) }) It("should not re-execute the run command", func() { - Expect(string(stdout)).To(ContainSubstring(executeBuildCommand)) - Expect(string(stdout)).ToNot(ContainSubstring(executeRunCommand)) + Expect(string(devSession.StdOut)).To(ContainSubstring(executeBuildCommand)) + Expect(string(devSession.StdOut)).ToNot(ContainSubstring(executeRunCommand)) By("telling the user that odo is synchronizing the files", func() { - Expect(string(stdout)).Should(ContainSubstring("Syncing files into the container")) + Expect(string(devSession.StdOut)).Should(ContainSubstring("Syncing files into the container")) }) }) }) @@ -3761,14 +3729,13 @@ CMD ["npm", "start"] When("hotReload capable Build and Run commands are used with odo dev", helper.LabelPodmanIf(podman, func() { var devSession helper.DevSession - var stdout []byte var executeRunCommand = "Executing the application (command: run)" var executeBuildCommand = "Building your application" BeforeEach(func() { helper.CopyExample(filepath.Join("source", "angular"), commonVar.Context) helper.UpdateDevfileContent(filepath.Join(commonVar.Context, "devfile.yaml"), []helper.DevfileUpdater{helper.DevfileMetadataNameSetter(cmpName)}) var err error - devSession, stdout, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -3781,28 +3748,27 @@ CMD ["npm", "start"] }) It("should execute the build and run commands", func() { - Expect(string(stdout)).To(ContainSubstring(executeBuildCommand)) - Expect(string(stdout)).To(ContainSubstring(executeRunCommand)) + Expect(string(devSession.StdOut)).To(ContainSubstring(executeBuildCommand)) + Expect(string(devSession.StdOut)).To(ContainSubstring(executeRunCommand)) By("telling the user that odo is synchronizing the files", func() { - Expect(string(stdout)).Should(ContainSubstring("Syncing files into the container")) + Expect(string(devSession.StdOut)).Should(ContainSubstring("Syncing files into the container")) }) }) When("a source file is modified", func() { BeforeEach(func() { helper.ReplaceString(filepath.Join(commonVar.Context, "src", "index.html"), "DevfileStackNodejsAngular", "Devfile Stack Nodejs Angular") - var err error - stdout, _, _, err = devSession.WaitSync() - Expect(err).Should(Succeed(), stdout) + err := devSession.WaitSync() + Expect(err).Should(Succeed(), devSession.StdOut) }) It("should not re-execute the run command", func() { - Expect(string(stdout)).ToNot(ContainSubstring(executeBuildCommand)) - Expect(string(stdout)).ToNot(ContainSubstring(executeRunCommand)) + Expect(string(devSession.StdOut)).ToNot(ContainSubstring(executeBuildCommand)) + Expect(string(devSession.StdOut)).ToNot(ContainSubstring(executeRunCommand)) By("telling the user that odo is synchronizing the files", func() { - Expect(string(stdout)).Should(ContainSubstring("Syncing files into the container")) + Expect(string(devSession.StdOut)).Should(ContainSubstring("Syncing files into the container")) }) }) }) @@ -3825,7 +3791,7 @@ CMD ["npm", "start"] var devSession helper.DevSession BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -4041,7 +4007,7 @@ CMD ["npm", "start"] var devSession helper.DevSession BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -4112,7 +4078,7 @@ CMD ["npm", "start"] It("should override the content in the pod it creates for the component on the cluster", func() { err := helper.RunDevMode(helper.DevSessionOpts{ RunOnPodman: ctx.podman, - }, func(session *gexec.Session, outContents, _ []byte, _ map[string]string) { + }, func(session *gexec.Session, outContents, _ string, _ map[string]string) { component := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) podOut := component.GetPodDef() ctx.checkFunc(podOut) @@ -4143,16 +4109,16 @@ CMD ["npm", "start"] helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "registry.access.redhat.com/ubi8/nodejs", "registry.access.redhat.com/ubi8/nose") }) It("should fail with an error", func() { - session, stdout, _, _, err := helper.StartDevMode(helper.DevSessionOpts{ + devSession, err := helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: true, }) Expect(err).ToNot(HaveOccurred()) defer func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }() - helper.MatchAllInOutput(string(stdout), []string{"Complete Podman output", "registry.access.redhat.com/ubi8/nose", "Repo not found"}) + helper.MatchAllInOutput(devSession.StdOut, []string{"Complete Podman output", "registry.access.redhat.com/ubi8/nose", "Repo not found"}) }) }) @@ -4195,16 +4161,11 @@ CMD ["npm", "start"] When("running on default cluster platform", func() { var devSession helper.DevSession - var stdout, stderr string - var ports map[string]string BeforeEach(func() { - var bOut, bErr []byte var err error - devSession, bOut, bErr, ports, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ShouldNot(HaveOccurred()) - stdout = string(bOut) - stderr = string(bErr) }) AfterEach(func() { @@ -4214,16 +4175,16 @@ CMD ["npm", "start"] It("should port-forward successfully", func() { By("not displaying warning message for loopback port", func() { - Expect(stderr).ShouldNot(ContainSubstring("Detected that the following port(s) can be reached only via the container loopback interface")) + Expect(devSession.ErrOut).ShouldNot(ContainSubstring("Detected that the following port(s) can be reached only via the container loopback interface")) }) By("forwarding both loopback and non-loopback ports", func() { - Expect(ports).Should(HaveLen(2)) - Expect(ports).Should(SatisfyAll(HaveKey("3000"), HaveKey("3001"))) + Expect(devSession.Endpoints).Should(HaveLen(2)) + Expect(devSession.Endpoints).Should(SatisfyAll(HaveKey("3000"), HaveKey("3001"))) }) By("displaying both loopback and non-loopback ports as forwarded", func() { - Expect(stdout).Should(SatisfyAll( - ContainSubstring("Forwarding from %s -> 3000", ports["3000"]), - ContainSubstring("Forwarding from %s -> 3001", ports["3001"]))) + Expect(devSession.StdOut).Should(SatisfyAll( + ContainSubstring("Forwarding from %s -> 3000", devSession.Endpoints["3000"]), + ContainSubstring("Forwarding from %s -> 3001", devSession.Endpoints["3001"]))) }) By("reaching both loopback and non-loopback ports via port-forwarding", func() { for port, body := range map[int]string{ @@ -4231,7 +4192,7 @@ CMD ["npm", "start"] 3001: "Hello from Node.js Admin Application!", } { Eventually(func(g Gomega) { - g.Expect(ports[strconv.Itoa(port)]).Should(haveHttpResponse(http.StatusOK, body)) + g.Expect(devSession.Endpoints[strconv.Itoa(port)]).Should(haveHttpResponse(http.StatusOK, body)) }).WithTimeout(60 * time.Second).WithPolling(3 * time.Second).Should(Succeed()) } }) @@ -4248,32 +4209,27 @@ CMD ["npm", "start"] }) It("should error out if not ignoring localhost", func() { - session, _, stderr, _, err := helper.StartDevMode(helper.DevSessionOpts{ + devSession, err := helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: true, }) Expect(err).ToNot(HaveOccurred()) defer func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }() - Expect(stderr).Should(ContainSubstring("Detected that the following port(s) can be reached only via the container loopback interface: admin (3001)")) + Expect(devSession.ErrOut).Should(ContainSubstring("Detected that the following port(s) can be reached only via the container loopback interface: admin (3001)")) }) When("ignoring localhost", func() { var devSession helper.DevSession - var stderr string - var ports map[string]string - BeforeEach(func() { - var bErr []byte var err error - devSession, _, bErr, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: true, CmdlineArgs: []string{"--ignore-localhost"}, }) Expect(err).ShouldNot(HaveOccurred()) - stderr = string(bErr) }) AfterEach(func() { @@ -4283,7 +4239,7 @@ CMD ["npm", "start"] It("should port-forward successfully", func() { By("displaying warning message for loopback port", func() { - Expect(stderr).Should(ContainSubstring("Detected that the following port(s) can be reached only via the container loopback interface: admin (3001)")) + Expect(devSession.ErrOut).Should(ContainSubstring("Detected that the following port(s) can be reached only via the container loopback interface: admin (3001)")) }) By("creating a pod with a single container pod because --forward-localhost is false", func() { podDef := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner).GetPodDef() @@ -4292,14 +4248,14 @@ CMD ["npm", "start"] }) By("reaching the local port for the non-loopback interface", func() { Eventually(func(g Gomega) { - g.Expect(ports["3000"]).Should(haveHttpResponse(http.StatusOK, "Hello from Node.js Application!")) + g.Expect(devSession.Endpoints["3000"]).Should(haveHttpResponse(http.StatusOK, "Hello from Node.js Application!")) }).WithTimeout(60 * time.Second).WithPolling(3 * time.Second).Should(Succeed()) }) By("not succeeding to reach the local port for the loopback interface", func() { // By design, Podman will not forward to container apps listening on localhost. // See https://github.com/redhat-developer/odo/issues/6510 and https://github.com/containers/podman/issues/17353 Consistently(func() error { - _, err := http.Get("http://" + ports["3001"]) + _, err := http.Get("http://" + devSession.Endpoints["3001"]) return err }).Should(HaveOccurred()) }) @@ -4308,22 +4264,21 @@ CMD ["npm", "start"] When("making changes in the project source code during the dev session", func() { BeforeEach(func() { helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "Hello from", "Hiya from the updated") - var err error - _, _, ports, err = devSession.WaitSync() + err := devSession.WaitSync() Expect(err).ShouldNot(HaveOccurred()) }) It("should port-forward successfully", func() { By("reaching the local port for the non-loopback interface", func() { Eventually(func(g Gomega) { - g.Expect(ports["3000"]).Should(haveHttpResponse(http.StatusOK, "Hiya from the updated Node.js Application!")) + g.Expect(devSession.Endpoints["3000"]).Should(haveHttpResponse(http.StatusOK, "Hiya from the updated Node.js Application!")) }).WithTimeout(60 * time.Second).WithPolling(3 * time.Second).Should(Succeed()) }) By("not succeeding to reach the local port for the loopback interface", func() { // By design, Podman will not forward to container apps listening on localhost. // See https://github.com/redhat-developer/odo/issues/6510 and https://github.com/containers/podman/issues/17353 Consistently(func() error { - _, err := http.Get("http://" + ports["3001"]) + _, err := http.Get("http://" + devSession.Endpoints["3001"]) return err }).Should(HaveOccurred()) }) @@ -4333,19 +4288,13 @@ CMD ["npm", "start"] When("forwarding localhost", func() { var devSession helper.DevSession - var stdout, stderr string - var ports map[string]string - BeforeEach(func() { - var bOut, bErr []byte var err error - devSession, bOut, bErr, ports, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: true, CmdlineArgs: []string{"--forward-localhost"}, }) Expect(err).ShouldNot(HaveOccurred()) - stdout = string(bOut) - stderr = string(bErr) }) AfterEach(func() { @@ -4355,7 +4304,7 @@ CMD ["npm", "start"] It("should port-forward successfully", func() { By("not displaying warning message for loopback port", func() { - for _, output := range []string{stdout, stderr} { + for _, output := range []string{devSession.StdOut, devSession.ErrOut} { Expect(output).ShouldNot(ContainSubstring("Detected that the following port(s) can be reached only via the container loopback interface")) } }) @@ -4376,12 +4325,12 @@ CMD ["npm", "start"] }) By("reaching the local port for the non-loopback interface", func() { Eventually(func(g Gomega) { - g.Expect(ports["3000"]).Should(haveHttpResponse(http.StatusOK, "Hello from Node.js Application!")) + g.Expect(devSession.Endpoints["3000"]).Should(haveHttpResponse(http.StatusOK, "Hello from Node.js Application!")) }).WithTimeout(60 * time.Second).WithPolling(3 * time.Second).Should(Succeed()) }) By("reaching the local port for the loopback interface", func() { Eventually(func(g Gomega) { - g.Expect(ports["3001"]).Should(haveHttpResponse(http.StatusOK, "Hello from Node.js Admin Application!")) + g.Expect(devSession.Endpoints["3001"]).Should(haveHttpResponse(http.StatusOK, "Hello from Node.js Admin Application!")) }).WithTimeout(60 * time.Second).WithPolling(3 * time.Second).Should(Succeed()) }) }) @@ -4389,20 +4338,19 @@ CMD ["npm", "start"] When("making changes in the project source code during the dev session", func() { BeforeEach(func() { helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "Hello from", "Hiya from the updated") - var err error - _, _, ports, err = devSession.WaitSync() + err := devSession.WaitSync() Expect(err).ShouldNot(HaveOccurred()) }) It("should port-forward successfully", func() { By("reaching the local port for the non-loopback interface", func() { Eventually(func(g Gomega) { - g.Expect(ports["3000"]).Should(haveHttpResponse(http.StatusOK, "Hiya from the updated Node.js Application!")) + g.Expect(devSession.Endpoints["3000"]).Should(haveHttpResponse(http.StatusOK, "Hiya from the updated Node.js Application!")) }).WithTimeout(60 * time.Second).WithPolling(3 * time.Second).Should(Succeed()) }) By("reaching the local port for the loopback interface", func() { Eventually(func(g Gomega) { - g.Expect(ports["3001"]).Should(haveHttpResponse(http.StatusOK, "Hiya from the updated Node.js Admin Application!")) + g.Expect(devSession.Endpoints["3001"]).Should(haveHttpResponse(http.StatusOK, "Hiya from the updated Node.js Admin Application!")) }).WithTimeout(60 * time.Second).WithPolling(3 * time.Second).Should(Succeed()) }) }) @@ -4425,10 +4373,7 @@ CMD ["npm", "start"] When("running odo dev with some components not referenced in the Devfile", func() { var devSession helper.DevSession - var stdout, stderr string - BeforeEach(func() { - var bOut, bErr []byte var err error var envvars []string if podman { @@ -4436,13 +4381,11 @@ CMD ["npm", "start"] } else { envvars = append(envvars, "PODMAN_CMD=echo") } - devSession, bOut, bErr, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, EnvVars: envvars, }) Expect(err).ShouldNot(HaveOccurred()) - stdout = string(bOut) - stderr = string(bErr) }) AfterEach(func() { @@ -4454,7 +4397,7 @@ CMD ["npm", "start"] It("should create the appropriate resources", func() { if podman { - k8sOcComponents := helper.ExtractK8sAndOcComponentsFromOutputOnPodman(stderr) + k8sOcComponents := helper.ExtractK8sAndOcComponentsFromOutputOnPodman(devSession.ErrOut) By("handling Kubernetes/OpenShift components that would have been created automatically", func() { Expect(k8sOcComponents).Should(ContainElements( "k8s-deploybydefault-true-and-referenced", @@ -4484,7 +4427,7 @@ CMD ["npm", "start"] "ocp-deploybydefault-true-and-referenced", "ocp-deploybydefault-true-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) By("automatically applying non-referenced Kubernetes/OpenShift components with deployByDefault not set", func() { @@ -4492,7 +4435,7 @@ CMD ["npm", "start"] "k8s-deploybydefault-not-set-and-not-referenced", "ocp-deploybydefault-not-set-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) By("not applying Kubernetes/OpenShift components with deployByDefault=false", func() { @@ -4502,11 +4445,11 @@ CMD ["npm", "start"] "ocp-deploybydefault-false-and-referenced", "ocp-deploybydefault-false-and-not-referenced", } { - Expect(stdout).ShouldNot(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("Creating resource Pod/%s", l)) } }) By("not applying referenced Kubernetes/OpenShift components with deployByDefault unset", func() { - Expect(stdout).ShouldNot(ContainSubstring("Creating resource Pod/k8s-deploybydefault-not-set-and-referenced")) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("Creating resource Pod/k8s-deploybydefault-not-set-and-referenced")) }) } @@ -4520,32 +4463,29 @@ CMD ["npm", "start"] "autobuild-true-and-referenced", "autobuild-true-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) } }) By("automatically applying non-referenced Image components with autoBuild not set", func() { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:autobuild-not-set-and-not-referenced", imageMessagePrefix)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:autobuild-not-set-and-not-referenced", imageMessagePrefix)) }) By("not applying image components with autoBuild=false", func() { for _, tag := range []string{ "autobuild-false-and-referenced", "autobuild-false-and-not-referenced", } { - Expect(stdout).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:%s", tag)) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:%s", tag)) } }) By("not applying referenced Image components with deployByDefault unset", func() { - Expect(stdout).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:autobuild-not-set-and-referenced")) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:autobuild-not-set-and-referenced")) }) }) }) When("running odo dev with some components referenced in the Devfile", func() { var devSession helper.DevSession - var stdout, stderr string - BeforeEach(func() { - var bOut, bErr []byte var err error var envvars []string if podman { @@ -4553,14 +4493,12 @@ CMD ["npm", "start"] } else { envvars = append(envvars, "PODMAN_CMD=echo") } - devSession, bOut, bErr, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ CmdlineArgs: []string{"--run-command", "run-with-referenced-components"}, EnvVars: envvars, RunOnPodman: podman, }) Expect(err).ShouldNot(HaveOccurred()) - stdout = string(bOut) - stderr = string(bErr) }) AfterEach(func() { @@ -4572,7 +4510,7 @@ CMD ["npm", "start"] It("should create the appropriate resources", func() { if podman { - k8sOcComponents := helper.ExtractK8sAndOcComponentsFromOutputOnPodman(stderr) + k8sOcComponents := helper.ExtractK8sAndOcComponentsFromOutputOnPodman(devSession.ErrOut) By("handling Kubernetes/OpenShift components that would have been created automatically", func() { Expect(k8sOcComponents).Should(ContainElements( "k8s-deploybydefault-true-and-referenced", @@ -4611,7 +4549,7 @@ CMD ["npm", "start"] "ocp-deploybydefault-false-and-referenced", "ocp-deploybydefault-not-set-and-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) @@ -4622,7 +4560,7 @@ CMD ["npm", "start"] "ocp-deploybydefault-true-and-referenced", "ocp-deploybydefault-true-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) By("automatically applying non-referenced Kubernetes/OpenShift components with deployByDefault not set", func() { @@ -4630,7 +4568,7 @@ CMD ["npm", "start"] "k8s-deploybydefault-not-set-and-not-referenced", "ocp-deploybydefault-not-set-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).Should(ContainSubstring("Creating resource Pod/%s", l)) } }) @@ -4639,7 +4577,7 @@ CMD ["npm", "start"] "k8s-deploybydefault-false-and-not-referenced", "ocp-deploybydefault-false-and-not-referenced", } { - Expect(stdout).ShouldNot(ContainSubstring("Creating resource Pod/%s", l)) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("Creating resource Pod/%s", l)) } }) } @@ -4655,7 +4593,7 @@ CMD ["npm", "start"] "autobuild-false-and-referenced", "autobuild-not-set-and-referenced", } { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) } }) By("automatically applying image components with autoBuild=true", func() { @@ -4663,14 +4601,14 @@ CMD ["npm", "start"] "autobuild-true-and-referenced", "autobuild-true-and-not-referenced", } { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:%s", imageMessagePrefix, tag)) } }) By("automatically applying non-referenced Image components with autoBuild not set", func() { - Expect(stdout).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:autobuild-not-set-and-not-referenced", imageMessagePrefix)) + Expect(devSession.StdOut).Should(ContainSubstring("%s: localhost:5000/odo-dev/node:autobuild-not-set-and-not-referenced", imageMessagePrefix)) }) By("not applying non-referenced image components with autoBuild=false", func() { - Expect(stdout).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:autobuild-false-and-not-referenced")) + Expect(devSession.StdOut).ShouldNot(ContainSubstring("localhost:5000/odo-dev/node:autobuild-false-and-not-referenced")) }) }) }) @@ -4724,7 +4662,6 @@ CMD ["npm", "start"] When("running odo dev", func() { var devSession helper.DevSession - var stdout string BeforeEach(func() { var env []string @@ -4733,14 +4670,12 @@ CMD ["npm", "start"] } else { env = append(env, "PODMAN_CMD=echo") } - var outB []byte var err error - devSession, outB, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, EnvVars: env, }) Expect(err).ShouldNot(HaveOccurred()) - stdout = string(outB) }) AfterEach(func() { @@ -4756,7 +4691,7 @@ CMD ["npm", "start"] imageMessagePrefix = "Building Image" } - lines, err := helper.ExtractLines(stdout) + lines, err := helper.ExtractLines(devSession.StdOut) Expect(err).ShouldNot(HaveOccurred()) var replacementImageName string @@ -4916,7 +4851,7 @@ CMD ["npm", "start"] for _, noCommands := range []bool{false, true} { noCommands := noCommands It(fmt.Sprintf("should start the Dev Session with --no-commands=%v", noCommands), func() { - devSession, stdout, stderr, ports, err := helper.StartDevMode(helper.DevSessionOpts{ + devSession, err := helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, NoCommands: noCommands, }) @@ -4927,7 +4862,7 @@ CMD ["npm", "start"] }() By("syncing the files", func() { - Expect(string(stdout)).Should(ContainSubstring("Syncing files into the container")) + Expect(devSession.StdOut).Should(ContainSubstring("Syncing files into the container")) component := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner) execResult, _ := component.Exec("runtime", []string{"ls", "-lai", "/projects"}, pointer.Bool(true)) @@ -4940,27 +4875,27 @@ CMD ["npm", "start"] }) By("not executing any build command", func() { - for _, out := range [][]byte{stdout, stderr} { + for _, out := range []string{devSession.StdOut, devSession.ErrOut} { Expect(string(out)).ShouldNot(ContainSubstring("Building your application in container on cluster")) } }) By("not executing any run command", func() { - for _, out := range [][]byte{stdout, stderr} { + for _, out := range []string{devSession.StdOut, devSession.ErrOut} { Expect(string(out)).ShouldNot(ContainSubstring("Executing the application")) } }) if !noCommands { By("warning about missing default run command", func() { - Expect(string(stderr)).Should(ContainSubstring("Missing default run command")) + Expect(devSession.ErrOut).Should(ContainSubstring("Missing default run command")) }) } By("setting up port forwarding", func() { - Expect(ports).ShouldNot(BeEmpty()) - _, ok := ports["3000"] - Expect(ok).To(BeTrue(), fmt.Sprintf("missing port forwarded for 3000: %v", ports)) + Expect(devSession.Endpoints).ShouldNot(BeEmpty()) + _, ok := devSession.Endpoints["3000"] + Expect(ok).To(BeTrue(), fmt.Sprintf("missing port forwarded for 3000: %v", devSession.Endpoints)) }) }) } diff --git a/tests/integration/cmd_devfile_deploy_test.go b/tests/integration/cmd_devfile_deploy_test.go index 405fe9f05be..3dceb340d08 100644 --- a/tests/integration/cmd_devfile_deploy_test.go +++ b/tests/integration/cmd_devfile_deploy_test.go @@ -159,18 +159,18 @@ var _ = Describe("odo devfile deploy command tests", func() { }) It("should run odo dev successfully", func() { - session, _, _, _, err := helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err := helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) - session.Kill() - session.WaitEnd() + devSession.Kill() + devSession.WaitEnd() }) When("running and stopping odo dev", func() { BeforeEach(func() { - session, _, _, _, err := helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err := helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ShouldNot(HaveOccurred()) - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) It("should not delete the resources created with odo deploy", func() { diff --git a/tests/integration/cmd_devfile_list_test.go b/tests/integration/cmd_devfile_list_test.go index 83cb64fa805..513e0171af9 100644 --- a/tests/integration/cmd_devfile_list_test.go +++ b/tests/integration/cmd_devfile_list_test.go @@ -132,7 +132,7 @@ var _ = Describe("odo list with devfile", func() { When("dev is running on cluster", func() { BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { @@ -231,7 +231,7 @@ var _ = Describe("odo list with devfile", func() { When("dev is running on podman", Label(helper.LabelPodman), func() { BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: true, }) Expect(err).ToNot(HaveOccurred()) @@ -323,7 +323,7 @@ var _ = Describe("odo list with devfile", func() { var devSession helper.DevSession BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { @@ -353,7 +353,7 @@ var _ = Describe("odo list with devfile", func() { var devSession helper.DevSession BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { diff --git a/tests/integration/cmd_logs_test.go b/tests/integration/cmd_logs_test.go index 5f38f2270ce..63abf488753 100644 --- a/tests/integration/cmd_logs_test.go +++ b/tests/integration/cmd_logs_test.go @@ -119,10 +119,10 @@ var _ = Describe("odo logs command tests", func() { podman := podman When("running in Dev mode", helper.LabelPodmanIf(podman, func() { var devSession helper.DevSession - var err error BeforeEach(func() { - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + var err error + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, }) Expect(err).ToNot(HaveOccurred()) @@ -231,9 +231,9 @@ var _ = Describe("odo logs command tests", func() { When("running in both Dev and Deploy mode", func() { var devSession helper.DevSession - var err error BeforeEach(func() { - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + var err error + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass() Eventually(func() bool { diff --git a/tests/integration/cmd_remove_binding_test.go b/tests/integration/cmd_remove_binding_test.go index 5aa9b76d91f..3faa9b5854e 100644 --- a/tests/integration/cmd_remove_binding_test.go +++ b/tests/integration/cmd_remove_binding_test.go @@ -52,20 +52,20 @@ var _ = Describe("odo remove binding command tests", func() { }) When("odo dev is running", func() { - var session helper.DevSession + var devSession helper.DevSession BeforeEach(func() { var err error - session, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{}) + devSession, err = helper.StartDevMode(helper.DevSessionOpts{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { - session.Stop() - session.WaitEnd() + devSession.Stop() + devSession.WaitEnd() }) When("binding is removed", func() { BeforeEach(func() { helper.Cmd("odo", "remove", "binding", "--name", bindingName).ShouldPass() - _, _, _, err := session.WaitSync() + err := devSession.WaitSync() Expect(err).ToNot(HaveOccurred()) }) It("should have led odo dev to delete ServiceBinding from the cluster", func() { diff --git a/tests/integration/cmd_run_test.go b/tests/integration/cmd_run_test.go index 7580b5319e4..cb2c1a67601 100644 --- a/tests/integration/cmd_run_test.go +++ b/tests/integration/cmd_run_test.go @@ -85,7 +85,7 @@ var _ = Describe("odo run command tests", func() { BeforeEach(func() { var err error - devSession, _, _, _, err = helper.StartDevMode(helper.DevSessionOpts{ + devSession, err = helper.StartDevMode(helper.DevSessionOpts{ RunOnPodman: podman, NoCommands: noCommands, })