Skip to content

Commit

Permalink
Test script customisation and removing duplicates from push test (red…
Browse files Browse the repository at this point in the history
…hat-developer#3645)

* Clean up and customise push test

* Removing duplicates in regular push test
  • Loading branch information
prietyc123 committed Aug 21, 2020
1 parent b410db9 commit 927826e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 81 deletions.
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 @@ -130,7 +130,7 @@ var _ = Describe("odo devfile push command tests", func() {
[]string{"stat", "/test/server.js"},
func(cmdOp string, err error) bool {
statErr = err
return true
return err == nil
},
)
Expect(statErr).ToNot(HaveOccurred())
Expand All @@ -155,7 +155,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 @@ -180,7 +180,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 @@ -206,7 +206,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 @@ -329,7 +329,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 @@ -343,7 +343,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 @@ -370,7 +370,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 @@ -493,7 +493,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 @@ -506,7 +506,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

0 comments on commit 927826e

Please sign in to comment.