diff --git a/tests/integration/devfile/cmd_dev_test.go b/tests/integration/devfile/cmd_dev_test.go index 0401dba0ed8..0870f514719 100644 --- a/tests/integration/devfile/cmd_dev_test.go +++ b/tests/integration/devfile/cmd_dev_test.go @@ -3,6 +3,7 @@ package devfile import ( "fmt" "io" + "io/ioutil" "net/http" "os" "path/filepath" @@ -1412,4 +1413,50 @@ var _ = Describe("odo dev command tests", func() { } }) }) + + When("a component with multiple endpoints is run", func() { + stateFile := ".odo/state.json" + var devSession helper.DevSession + BeforeEach(func() { + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project-with-multiple-endpoints"), commonVar.Context) + helper.Cmd("odo", "project", "set", commonVar.Project).ShouldPass() + helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-multiple-endpoints.yaml")).ShouldPass() + Expect(helper.VerifyFileExists(".odo/state.json")).To(BeFalse()) + var err error + devSession, _, _, _, err = helper.StartDevMode() + Expect(err).ToNot(HaveOccurred()) + }) + + AfterEach(func() { + // We stop the process so the process does not remain after the end of the tests + devSession.Kill() + devSession.WaitEnd() + }) + + It("should create a state file containing forwarded ports", func() { + Expect(helper.VerifyFileExists(stateFile)).To(BeTrue()) + contentJSON, err := ioutil.ReadFile(stateFile) + Expect(err).ToNot(HaveOccurred()) + helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.0.containerName", "runtime") + helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.1.containerName", "runtime") + helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.0.localAddress", "127.0.0.1") + helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.1.localAddress", "127.0.0.1") + helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.0.containerPort", "3000") + helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.1.containerPort", "4567") + }) + + When("odo dev is stopped", func() { + BeforeEach(func() { + devSession.Stop() + devSession.WaitEnd() + }) + + It("should remove forwarded ports from state file", func() { + Expect(helper.VerifyFileExists(stateFile)).To(BeTrue()) + contentJSON, err := ioutil.ReadFile(stateFile) + Expect(err).ToNot(HaveOccurred()) + helper.JsonPathContentIs(string(contentJSON), "forwardedPorts", "") + }) + }) + }) })