Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test script customisation and removing duplicates from push test #3645

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 25 additions & 72 deletions tests/integration/cmd_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ var _ = Describe("odo push command tests", func() {
Context("Test push outside of the current working direcory", func() {

// Change to "outside" the directory before running the below tests
var _ = BeforeEach(func() {
JustBeforeEach(func() {
currentWorkingDirectory = helper.Getwd()
helper.Chdir(context)
})

// Change back to the currentWorkingDirectory
var _ = AfterEach(func() {
JustAfterEach(func() {
helper.Chdir(currentWorkingDirectory)
})

Expand Down Expand Up @@ -192,9 +192,12 @@ var _ = Describe("odo push command tests", func() {
helper.HttpWaitFor("http://"+url, "UPDATED!", 30, 1)
})

It("should be able to create a file, push, delete, then push again propagating the deletions", func() {
It("should be able to create a file, push, delete, then push again propagating the deletions and build", func() {
helper.CmdShouldPass("git", "clone", "https://github.com/openshift/nodejs-ex", context+"/nodejs-ex")
helper.CmdShouldPass("odo", "component", "create", "nodejs", cmpName, "--project", project, "--context", context+"/nodejs-ex", "--app", appName)
helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex")
output := helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex")
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))

// Create a new file that we plan on deleting later...
newFilePath := filepath.Join(context, "nodejs-ex", "foobar.txt")
Expand Down Expand Up @@ -228,40 +231,6 @@ var _ = Describe("odo push command tests", func() {
helper.DontMatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"})
})

It("should build when a new file and a new folder is added in the directory", func() {
helper.CmdShouldPass("git", "clone", "https://github.com/openshift/nodejs-ex", context+"/nodejs-ex")
helper.CmdShouldPass("odo", "component", "create", "nodejs", cmpName, "--project", project, "--context", context+"/nodejs-ex", "--app", appName)
helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex")
output := helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex")

Expect(output).To(ContainSubstring("No file changes detected, skipping build"))

newFilePath := filepath.Join(context, "nodejs-ex", "new-example.html")
if err := helper.CreateFileWithContent(newFilePath, "<html>Hello</html>"); err != nil {
fmt.Printf("the new-example.html file was not created, reason %v", err.Error())
}

output = helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex")
Expect(output).To(Not(ContainSubstring("No file changes detected, skipping build")))

// get the name of running pod
podName := oc.GetRunningPodNameOfComp(cmpName, project)

// verify that the new file was pushed
envs := oc.GetEnvs(cmpName, appName, project)
dir := envs["ODO_S2I_DEPLOYMENT_DIR"]
stdOut := oc.ExecListDir(podName, project, dir)
Expect(stdOut).To(ContainSubstring(("README.md")))

// make a new folder and push
helper.MakeDir(filepath.Join(context, "nodejs-ex", "exampleDir"))
helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex")

// verify that the new file was pushed
stdOut = oc.ExecListDir(podName, project, dir)
Expect(stdOut).To(ContainSubstring(("exampleDir")))
})

It("should build when a file and a folder is renamed in the directory", func() {
helper.CmdShouldPass("git", "clone", "https://github.com/openshift/nodejs-ex", context+"/nodejs-ex")
helper.CmdShouldPass("odo", "component", "create", "nodejs", cmpName, "--project", project, "--context", context+"/nodejs-ex", "--app", appName)
Expand Down Expand Up @@ -301,27 +270,6 @@ var _ = Describe("odo push command tests", func() {
Expect(stdOut).To(ContainSubstring("testing"))
})

It("should not build when changes are detected in a ignored file", func() {
helper.CmdShouldPass("git", "clone", "https://github.com/openshift/nodejs-ex", context+"/nodejs-ex")
helper.CmdShouldPass("odo", "component", "create", "nodejs", cmpName, "--project", project, "--context", context+"/nodejs-ex", "--app", appName)

// create the .odoignore file and push
ignoreFilePath := filepath.Join(context, "nodejs-ex", ".odoignore")
if err := helper.CreateFileWithContent(ignoreFilePath, ".git\n*.md"); err != nil {
fmt.Printf("the .odoignore file was not created, reason %v", err.Error())
}
helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex")

// modify a ignored file and push
helper.ReplaceString(filepath.Join(context, "nodejs-ex", "README.md"), "This example will serve a welcome page", "This is a example welcome page!")
output := helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex")
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))

// test ignores using the flag
output = helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex", "--ignore", "*.md")
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))
})

It("should build when no changes are detected in the directory and force flag is enabled", func() {
helper.CmdShouldPass("git", "clone", "https://github.com/openshift/nodejs-ex", context+"/nodejs-ex")
helper.CmdShouldPass("odo", "component", "create", "nodejs", cmpName, "--project", project, "--context", context+"/nodejs-ex", "--app", appName)
Expand Down Expand Up @@ -448,11 +396,11 @@ var _ = Describe("odo push command tests", func() {
})

Context("when .odoignore file exists", func() {
It("should create and push the contents of a named component excluding the contents in .odoignore file", func() {
It("should create and push the contents of a named component excluding the contents and changes detected in .odoignore file", func() {
helper.CmdShouldPass("git", "clone", "https://github.com/openshift/nodejs-ex", context+"/nodejs-ex")

ignoreFilePath := filepath.Join(context, "nodejs-ex", ".odoignore")
if err := helper.CreateFileWithContent(ignoreFilePath, ".git\ntests/\nREADME.md"); err != nil {
if err := helper.CreateFileWithContent(ignoreFilePath, ".git\n*.md"); err != nil {
fmt.Printf("the .odoignore file was not created, reason %v", err.Error())
}

Expand All @@ -469,13 +417,18 @@ var _ = Describe("odo push command tests", func() {
stdOut1 := oc.ExecListDir(podName, project, dir)
Expect(stdOut1).To(ContainSubstring("views"))

// verify that the tests was not pushed
stdOut2 := oc.ExecListDir(podName, project, dir)
Expect(stdOut2).To(Not(ContainSubstring(("tests"))))

// verify that the README.md file was not pushed
stdOut3 := oc.ExecListDir(podName, project, dir)
Expect(stdOut3).To(Not(ContainSubstring(("README.md"))))

// modify a ignored file and push
helper.ReplaceString(filepath.Join(context, "nodejs-ex", "README.md"), "This example will serve a welcome page", "This is a example welcome page!")
output := helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex")
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))

// test ignores using the flag
output = helper.CmdShouldPass("odo", "push", "--context", context+"/nodejs-ex", "--ignore", "*.md")
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))
})
})

Expand Down Expand Up @@ -504,18 +457,18 @@ var _ = Describe("odo push command tests", func() {
})

Context("when running odo push with flag --show-log", func() {
It("should be able to spam odo push without anything breaking", func() {
It("should be able to execute odo push consecutively without breaking anything", func() {
helper.CmdShouldPass("git", "clone", "https://github.com/openshift/nodejs-ex", context+"/nodejs-ex")
helper.CmdShouldPass("odo", "create", "nodejs", "nodejs", "--project", project, "--context", context+"/nodejs-ex")
// Iteration 1

// Run odo push in consecutive iteration
output := helper.CmdShouldPass("odo", "push", "--show-log", "--context", context+"/nodejs-ex")
Expect(output).To(Not(ContainSubstring("No file changes detected, skipping build")))
// Iteration 2
output = helper.CmdShouldPass("odo", "push", "--show-log", "--context", context+"/nodejs-ex")
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))
// Iteration 3
output = helper.CmdShouldPass("odo", "push", "--show-log", "--context", context+"/nodejs-ex")
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))

for i := 0; i <= 1; i++ {
output := helper.CmdShouldPass("odo", "push", "--show-log", "--context", context+"/nodejs-ex")
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))
}
})
})
})
18 changes: 9 additions & 9 deletions tests/integration/devfile/cmd_devfile_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var _ = Describe("odo devfile push command tests", func() {
[]string{"stat", "/test/server.js"},
func(cmdOp string, err error) bool {
statErr = err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove statErr = err

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are also verifying that err should not have occured here - https://github.com/openshift/odo/pull/3645/files#diff-c127bd883f89dd3a7abff6183ad9921dR157 . So keeping this in the test

return true
return err == nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for better approach

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This how we can avoid test script flakes.

},
)
Expect(statErr).ToNot(HaveOccurred())
Expand All @@ -154,7 +154,7 @@ var _ = Describe("odo devfile push command tests", func() {
[]string{"stat", "/projects/testfolder"},
func(cmdOp string, err error) bool {
statErr = err
return true
return err == nil
},
)
Expect(statErr).ToNot(HaveOccurred())
Expand All @@ -179,7 +179,7 @@ var _ = Describe("odo devfile push command tests", func() {
[]string{"stat", "/projects/testfolder"},
func(cmdOp string, err error) bool {
statErr = err
return true
return err == nil
},
)
Expect(statErr).ToNot(HaveOccurred())
Expand All @@ -205,7 +205,7 @@ var _ = Describe("odo devfile push command tests", func() {
[]string{"stat", "/projects/testfolder"},
func(cmdOp string, err error) bool {
statErr = err
return true
return err == nil
},
)
Expect(statErr).ToNot(HaveOccurred())
Expand Down Expand Up @@ -328,7 +328,7 @@ var _ = Describe("odo devfile push command tests", func() {
[]string{"stat", "/projects/server.js"},
func(cmdOp string, err error) bool {
statErr = err
return true
return err == nil
},
)
Expect(statErr).ToNot(HaveOccurred())
Expand All @@ -342,7 +342,7 @@ var _ = Describe("odo devfile push command tests", func() {
[]string{"stat", "/projects/server.js"},
func(cmdOp string, err error) bool {
statErr = err
return true
return err == nil
},
)
Expect(statErr).To(HaveOccurred())
Expand All @@ -369,7 +369,7 @@ var _ = Describe("odo devfile push command tests", func() {
func(cmdOp string, err error) bool {
cmdOutput = cmdOp
statErr = err
return true
return err == nil
},
)
Expect(statErr).ToNot(HaveOccurred())
Expand Down Expand Up @@ -492,7 +492,7 @@ var _ = Describe("odo devfile push command tests", func() {
func(cmdOp string, err error) bool {
cmdOutput = cmdOp
statErr = err
return true
return err == nil
},
)
Expect(statErr).ToNot(HaveOccurred())
Expand All @@ -505,7 +505,7 @@ var _ = Describe("odo devfile push command tests", func() {
[]string{"stat", "/data2"},
func(cmdOp string, err error) bool {
statErr = err
return true
return err == nil
},
)
Expect(statErr).ToNot(HaveOccurred())
Expand Down