Skip to content

Commit

Permalink
Incorporated feedback about When statements (#5244)
Browse files Browse the repository at this point in the history
* Incorporated feedfack about When statements

* Fived gofmt issues

* Incorporated additional feedback about use of when

* Replaced When for just an it for odo watch -h

* Updated When statement as per feedback and ran gofmt on file
  • Loading branch information
rnapoles-rh authored Nov 29, 2021
1 parent ac478e9 commit d72d0c6
Showing 1 changed file with 95 additions and 149 deletions.
244 changes: 95 additions & 149 deletions tests/integration/devfile/cmd_devfile_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,105 +31,59 @@ var _ = Describe("odo devfile watch command tests", func() {
helper.CommonAfterEach(commonVar)
})

Context("when running help for watch command", func() {
It("should display the help", func() {
appHelp := helper.Cmd("odo", "watch", "-h").ShouldPass().Out()
helper.MatchAllInOutput(appHelp, []string{"Watch for changes", "git components"})
})
It("should display the help when using -h flag", func() {
appHelp := helper.Cmd("odo", "watch", "-h").ShouldPass().Out()
helper.MatchAllInOutput(appHelp, []string{"Watch for changes", "git components"})
})

Context("when executing watch without pushing a devfile component", func() {
It("should fail", func() {
When("a component is created and not pushed", func() {
BeforeEach(func() {
helper.Chdir(commonVar.OriginalWorkingDirectory)
helper.Cmd("odo", "create", "--project", commonVar.Project, "--context", commonVar.Context, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-registry.yaml")).ShouldPass()
})
It("odo watch should fail", func() {
output := helper.Cmd("odo", "watch", "--context", commonVar.Context).ShouldFail().Err()
Expect(output).To(ContainSubstring("component does not exist. Please use `odo push` to create your component"))
})

It("should error out on devfile flag", func() {
helper.Cmd("odo", "watch", "--devfile", "invalid.yaml").ShouldFail()
})
})

Context("when executing odo watch after odo push", func() {
It("should listen for file changes", func() {
When("a component is created and pushed", func() {
BeforeEach(func() {
helper.Cmd("odo", "create", "--project", commonVar.Project, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()

helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)

output := helper.Cmd("odo", "push", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

watchFlag := ""
odoV2Watch := utils.OdoV2Watch{
CmpName: cmpName,
StringsToBeMatched: []string{"Executing devbuild command", "Executing devrun command"},
}
// odo watch and validate
utils.OdoWatch(odoV2Watch, commonVar.Project, commonVar.Context, watchFlag, commonVar.CliRunner, "kube")
})
})

Context("when executing odo watch after odo push with flag commands", func() {
It("should listen for file changes", func() {
helper.Cmd("odo", "create", "--project", commonVar.Project, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()

helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)

output := helper.Cmd("odo", "push", "--build-command", "build", "--run-command", "run", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

watchFlag := "--build-command build --run-command run"
watchFlag := ""
odoV2Watch := utils.OdoV2Watch{
CmpName: cmpName,
StringsToBeMatched: []string{"Executing build command", "Executing run command"},
StringsToBeMatched: []string{"Executing devbuild command", "Executing devrun command"},
}
// odo watch and validate
utils.OdoWatch(odoV2Watch, commonVar.Project, commonVar.Context, watchFlag, commonVar.CliRunner, "kube")
})
})

Context("when executing odo watch", func() {
It("should show validation errors if the devfile is incorrect", func() {
helper.Cmd("odo", "create", "--project", commonVar.Project, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()

helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)

output := helper.Cmd("odo", "push", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

session := helper.CmdRunner("odo", "watch")
defer session.Kill()

helper.WaitForOutputToContain("Waiting for something to change", 180, 10, session)

helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "kind: build", "kind: run")

helper.WaitForOutputToContain(watch.PushErrorString, 180, 10, session)

})
})

Context("when executing odo watch", func() {
It("should use the index information from previous push operation", func() {
helper.Cmd("odo", "create", "--project", commonVar.Project, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()

helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)

// 1) Push a generic project
output := helper.Cmd("odo", "push", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

// 2) Create a new file A
// Create a new file A
fileAPath, fileAText := helper.CreateSimpleFile(commonVar.Context, "my-file-", ".txt")

// 3) Odo watch that project
// Odo watch that project
session := helper.CmdRunner("odo", "watch")
defer session.Kill()

helper.WaitForOutputToContain("Waiting for something to change", 180, 10, session)

// 4) Change some other file B
// Change some other file B
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "App started", "App is super started")
helper.WaitForOutputToContain("Executing devrun command", 180, 10, session)

Expand All @@ -138,16 +92,8 @@ var _ = Describe("odo devfile watch command tests", func() {
// File should exist, and its content should match what we initially set it to
execResult := commonVar.CliRunner.Exec(podName, commonVar.Project, "cat", "/projects/"+filepath.Base(fileAPath))
Expect(execResult).To(ContainSubstring(fileAText))

})

It("should listen for file changes with delay set to 0", func() {
helper.Cmd("odo", "create", "--project", commonVar.Project, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()

helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)

output := helper.Cmd("odo", "push", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

watchFlag := "--delay 0"
odoV2Watch := utils.OdoV2Watch{
Expand All @@ -157,95 +103,20 @@ var _ = Describe("odo devfile watch command tests", func() {
// odo watch and validate
utils.OdoWatch(odoV2Watch, commonVar.Project, commonVar.Context, watchFlag, commonVar.CliRunner, "kube")
})

})

Context("when executing odo watch after odo push with debug flag", func() {
It("should be able to start a debug session after push with debug flag using odo watch and revert back after normal push", func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.Cmd("odo", "create", cmpName, "--project", commonVar.Project, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml")).ShouldPass()

// push with debug flag
output := helper.Cmd("odo", "push", "--debug", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

watchFlag := ""
// check if the normal debugRun command was executed
odoV2Watch := utils.OdoV2Watch{
CmpName: cmpName,
StringsToBeMatched: []string{"Executing devbuild command", "Executing debugrun command"},
}
// odo watch and validate if we can port forward successfully
utils.OdoWatchWithDebug(odoV2Watch, commonVar.Context, watchFlag)

// check the --debug-command flag
watchFlag = "--debug-command debug"
odoV2Watch.StringsToBeMatched = []string{"Executing debug command"}

// odo watch and validate if we can port forward successfully
utils.OdoWatchWithDebug(odoV2Watch, commonVar.Context, watchFlag)

// revert to normal odo push
watchFlag = ""
output = helper.Cmd("odo", "push", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

// check if the normal run command was executed
odoV2Watch = utils.OdoV2Watch{
CmpName: cmpName,
StringsToBeMatched: []string{"Executing devbuild command", "Executing devrun command"},
}
utils.OdoWatch(odoV2Watch, commonVar.Project, commonVar.Context, watchFlag, commonVar.CliRunner, "kube")

// check that the --debug-command fails when the component is not pushed using debug mode
output = helper.Cmd("odo", "watch", "--debug-command", "debug").WithRetry(1, 1).ShouldFail().Err()
Expect(output).To(ContainSubstring("please start the component in debug mode"))
})
})

Context("when executing odo watch after odo push with ignores flag", func() {
It("should be able to ignore the specified file, .git and odo-file-index.json ", func() {
helper.Cmd("odo", "create", "--project", commonVar.Project, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()

helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)

output := helper.Cmd("odo", "push", "--build-command", "build", "--run-command", "run", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

watchFlag := "--ignore doignoreme.txt"
odoV2Watch := utils.OdoV2Watch{
CmpName: cmpName,
StringsToBeMatched: []string{"donotignoreme.txt changed", "Executing devbuild command", "Executing devrun command"},
StringsNotToBeMatched: []string{"doignoreme.txt changed", "odo-file-index.json changed", ".git/index changed"},
}
// odo watch and validate
utils.OdoWatchWithIgnore(odoV2Watch, commonVar.Context, watchFlag)
})
})

Context("when executing odo watch", func() {
It("ensure that index information is updated by watch", func() {
helper.Cmd("odo", "create", "--project", commonVar.Project, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()

helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)

// 1) Push a generic project
output := helper.Cmd("odo", "push", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

indexAfterPush, err := util.ReadFileIndex(filepath.Join(commonVar.Context, ".odo", "odo-file-index.json"))
Expect(err).ToNot(HaveOccurred())

// 2) Odo watch that project
// Odo watch that project
session := helper.CmdRunner("odo", "watch")
defer session.Kill()

helper.WaitForOutputToContain("Waiting for something to change", 180, 10, session)

// 3) Create a new file A
// Create a new file A
fileAPath, _ := helper.CreateSimpleFile(commonVar.Context, "my-file-", ".txt")

// 4) Wait for the new file to exist in the index
// Wait for the new file to exist in the index
Eventually(func() bool {

newIndexAfterPush, readErr := util.ReadFileIndex(filepath.Join(commonVar.Context, ".odo", "odo-file-index.json"))
Expand All @@ -262,7 +133,7 @@ var _ = Describe("odo devfile watch command tests", func() {

}, 180, 10).Should(Equal(true))

// 5) Delete file A and verify that it disappears from the index
// Delete file A and verify that it disappears from the index
err = os.Remove(fileAPath)
Expect(err).ToNot(HaveOccurred())
Eventually(func() bool {
Expand Down Expand Up @@ -290,11 +161,11 @@ var _ = Describe("odo devfile watch command tests", func() {

}, 180, 10).Should(Equal(true))

// 6) Change server.js
// Change server.js
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "App started", "App is super started")
helper.WaitForOutputToContain("server.js", 180, 10, session)

// 7) Wait for the size values in the old and new index files to differ, indicating that watch has updated the index
// Wait for the size values in the old and new index files to differ, indicating that watch has updated the index
Eventually(func() bool {

newIndexAfterPush, err := util.ReadFileIndex(filepath.Join(commonVar.Context, ".odo", "odo-file-index.json"))
Expand Down Expand Up @@ -322,6 +193,81 @@ var _ = Describe("odo devfile watch command tests", func() {
}, 180, 10).Should(Equal(true))

})

})

When("a component is created and pushed using build-command and run-command flags", func() {
BeforeEach(func() {
helper.Cmd("odo", "create", "--project", commonVar.Project, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
output := helper.Cmd("odo", "push", "--build-command", "build", "--run-command", "run", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))
})
It("should be able to ignore the specified file, .git and odo-file-index.json ", func() {
watchFlag := "--ignore doignoreme.txt"
odoV2Watch := utils.OdoV2Watch{
CmpName: cmpName,
StringsToBeMatched: []string{"donotignoreme.txt changed", "Executing devbuild command", "Executing devrun command"},
StringsNotToBeMatched: []string{"doignoreme.txt changed", "odo-file-index.json changed", ".git/index changed"},
}
// odo watch and validate
utils.OdoWatchWithIgnore(odoV2Watch, commonVar.Context, watchFlag)
})

It("should listen for file changes", func() {
watchFlag := "--build-command build --run-command run"
odoV2Watch := utils.OdoV2Watch{
CmpName: cmpName,
StringsToBeMatched: []string{"Executing build command", "Executing run command"},
}
// odo watch and validate
utils.OdoWatch(odoV2Watch, commonVar.Project, commonVar.Context, watchFlag, commonVar.CliRunner, "kube")
})
})

When("a component is created and pushed in debug mode", func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.Cmd("odo", "create", cmpName, "--project", commonVar.Project, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml")).ShouldPass()

// push with debug flag
output := helper.Cmd("odo", "push", "--debug", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))
})
It("should be able to start a debug session after push with debug flag using odo watch and revert back after normal push", func() {
watchFlag := ""
// check if the normal debugRun command was executed
odoV2Watch := utils.OdoV2Watch{
CmpName: cmpName,
StringsToBeMatched: []string{"Executing devbuild command", "Executing debugrun command"},
}
// odo watch and validate if we can port forward successfully
utils.OdoWatchWithDebug(odoV2Watch, commonVar.Context, watchFlag)

// check the --debug-command flag
watchFlag = "--debug-command debug"
odoV2Watch.StringsToBeMatched = []string{"Executing debug command"}

// odo watch and validate if we can port forward successfully
utils.OdoWatchWithDebug(odoV2Watch, commonVar.Context, watchFlag)

// revert to normal odo push
watchFlag = ""
output := helper.Cmd("odo", "push", "--project", commonVar.Project).ShouldPass().Out()
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

// check if the normal run command was executed
odoV2Watch = utils.OdoV2Watch{
CmpName: cmpName,
StringsToBeMatched: []string{"Executing devbuild command", "Executing devrun command"},
}
utils.OdoWatch(odoV2Watch, commonVar.Project, commonVar.Context, watchFlag, commonVar.CliRunner, "kube")

// check that the --debug-command fails when the component is not pushed using debug mode
output = helper.Cmd("odo", "watch", "--debug-command", "debug").WithRetry(1, 1).ShouldFail().Err()
Expect(output).To(ContainSubstring("please start the component in debug mode"))
})

})

})

0 comments on commit d72d0c6

Please sign in to comment.