From fa63a0269c18e583dd2fab500bf2c237c14653a9 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 16:46:15 +0900 Subject: [PATCH] Add collapse test for nesting orbs and local commands, etc --- cmd/collapse_test.go | 21 +++- .../hugo-collapse/{out.yml => result.yml} | 0 .../result.yml | 112 ++++++++++++++++++ .../test/build.yml | 71 +++++++++++ .../test/commands/say.yml | 8 ++ .../test/executors/parallel.yml | 1 + .../test/jobs/sayhello.yml | 10 ++ .../test/orbs/foo/commands/zomg.yml | 7 ++ .../test/orbs/foo/orb.yml | 10 ++ 9 files changed, 239 insertions(+), 1 deletion(-) rename cmd/testdata/hugo-collapse/{out.yml => result.yml} (100%) create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/result.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/build.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/commands/say.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/executors/parallel.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/jobs/sayhello.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/commands/zomg.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/orb.yml diff --git a/cmd/collapse_test.go b/cmd/collapse_test.go index 736d7087e..4c6a9d0ff 100644 --- a/cmd/collapse_test.go +++ b/cmd/collapse_test.go @@ -54,7 +54,26 @@ var _ = Describe("collapse with testdata", func() { BeforeEach(func() { var err error command = exec.Command(pathCLI, "collapse", "-r", "testdata/hugo-collapse/.circleci") - results, err = ioutil.ReadFile("testdata/hugo-collapse/out.yml") + results, err = ioutil.ReadFile("testdata/hugo-collapse/result.yml") + Expect(err).ShouldNot(HaveOccurred()) + }) + + It("collapse all YAML contents as expected", func() { + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) + session.Wait() + Expect(err).ShouldNot(HaveOccurred()) + Eventually(session.Err.Contents()).Should(BeEmpty()) + Eventually(session.Out.Contents()).Should(MatchYAML(results)) + Eventually(session).Should(gexec.Exit(0)) + }) + }) + + Describe("local orbs folder with mixed inline and local commands, jobs, etc", func() { + BeforeEach(func() { + var err error + var path string = "nested-orbs-and-local-commands-etc" + command = exec.Command(pathCLI, "collapse", "-r", filepath.Join("testdata", path, "test")) + results, err = ioutil.ReadFile(filepath.Join("testdata", path, "result.yml")) Expect(err).ShouldNot(HaveOccurred()) }) diff --git a/cmd/testdata/hugo-collapse/out.yml b/cmd/testdata/hugo-collapse/result.yml similarity index 100% rename from cmd/testdata/hugo-collapse/out.yml rename to cmd/testdata/hugo-collapse/result.yml diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/result.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/result.yml new file mode 100644 index 000000000..f34c24283 --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/result.yml @@ -0,0 +1,112 @@ +commands: + foo: + parameters: + mybool: + default: true + type: boolean + steps: + - run: echo in foo + - when: + condition: << parameters.mybool >> + steps: + - run: echo bool is true + - unless: + condition: << parameters.mybool >> + steps: + - run: echo bool is false + say: + description: A simple command that echoes whatever is passed + parameters: + saywhat: + description: What shall we say? + type: string + steps: + - run: echo << parameters.saywhat >> +executors: + parallel: + parallelism: 4 +jobs: + bar: + machine: + docker_layer_caching: << parameters.mybool >> + enabled: << parameters.mybool >> + parameters: + mybool: + default: false + type: boolean + myotherbool: + default: false + type: boolean + mysteps: + default: [] + type: steps + steps: + - checkout + - when: + condition: << parameters.mybool >> + steps: + - << parameters.mysteps >> + - when: + condition: << parameters.mybool >> + steps: + - foo: + mybool: << parameters.myotherbool >> + build-false: + machine: true + steps: + - foo: + mybool: false + build-true: + machine: true + steps: + - foo + sayhello: + description: A job that does very little other than demonstrate what a parameterized + job looks like + machine: true + parameters: + saywhat: + default: World + description: To whom shall we say hello? + type: string + steps: + - say: + saywhat: Hello << parameters.saywhat >> +orbs: + foo: + commands: + zomg: + description: a command inside a folder in an orb + parameters: + tm: + description: Tell me something. + type: string + steps: + - run: echo "You don't say... << parameters.saywhat >>" + description: A simple encapsulation of common tasks in Hugo + executors: + default: + docker: + - image: cibuilds/hugo:<< parameters.image >> + parameters: + tag: + description: The tag to use on the image + type: string +version: 2 +workflows: + version: 2 + workflow: + jobs: + - build-true + - build-false + - bar: + mybool: true + myotherbool: false + - bar: + mybool: false + myotherbool: true + - bar: + mybool: true + mysteps: + - run: echo i am a steps param, hear me shout + diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/build.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/build.yml new file mode 100644 index 000000000..b09c6f244 --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/build.yml @@ -0,0 +1,71 @@ +version: 2 + +commands: + foo: + parameters: + mybool: + type: boolean + default: true + steps: + - run: "echo in foo" + - when: + condition: << parameters.mybool >> + steps: + - run: echo bool is true + - unless: + condition: << parameters.mybool >> + steps: + - run: echo bool is false + +jobs: + build-true: + machine: true + steps: + - foo + build-false: + machine: true + steps: + - foo: + mybool: false + bar: + parameters: + mybool: + type: boolean + default: false + myotherbool: + type: boolean + default: false + mysteps: + type: steps + default: [] + machine: + docker_layer_caching: << parameters.mybool >> + enabled: << parameters.mybool >> + steps: + - checkout + - when: + condition: << parameters.mybool >> + steps: + - << parameters.mysteps >> + - when: + condition: << parameters.mybool >> + steps: + - foo: + mybool: << parameters.myotherbool >> + +workflows: + version: 2 + workflow: + jobs: + - build-true + - build-false + - bar: + mybool: true + myotherbool: false + - bar: + mybool: false + myotherbool: true + - bar: + mybool: true + mysteps: + - run: echo i am a steps param, hear me shout diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/commands/say.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/commands/say.yml new file mode 100644 index 000000000..36d54858c --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/commands/say.yml @@ -0,0 +1,8 @@ +description: "A simple command that echoes whatever is passed" +parameters: + saywhat: + description: "What shall we say?" + type: string +steps: + # note: the interpolation syntax is subject to change + - run: echo << parameters.saywhat >> diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/executors/parallel.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/executors/parallel.yml new file mode 100644 index 000000000..28c7f4b4d --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/executors/parallel.yml @@ -0,0 +1 @@ +parallelism: 4 diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/jobs/sayhello.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/jobs/sayhello.yml new file mode 100644 index 000000000..2be3c054c --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/jobs/sayhello.yml @@ -0,0 +1,10 @@ +description: A job that does very little other than demonstrate what a parameterized job looks like +parameters: + saywhat: + description: "To whom shall we say hello?" + type: string + default: "World" +machine: true +steps: + - say: + saywhat: Hello << parameters.saywhat >> diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/commands/zomg.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/commands/zomg.yml new file mode 100644 index 000000000..11289f015 --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/commands/zomg.yml @@ -0,0 +1,7 @@ +description: "a command inside a folder in an orb" +parameters: + tm: + description: "Tell me something." + type: string +steps: + - run: echo "You don't say... << parameters.saywhat >>" diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/orb.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/orb.yml new file mode 100644 index 000000000..d12c0a238 --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/orb.yml @@ -0,0 +1,10 @@ +description: "A simple encapsulation of common tasks in Hugo" + +executors: + default: + parameters: + tag: + description: "The tag to use on the image" + type: string + docker: + - image: cibuilds/hugo:<< parameters.image >>