From 998a25864b6ba4dd710548b43ca4f0eea28665fd Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 16:26:19 +0900 Subject: [PATCH] Add testdata for integration testing collapse command with hugo orb --- cmd/collapse_test.go | 33 +++--- .../hugo-collapse/.circleci/config.yml | 4 + .../hugo-collapse/.circleci/orbs/.DS_Store | 0 .../.circleci/orbs/hugo/README.md | 3 + .../orbs/hugo/commands/build-hugo.yml | 24 ++++ .../orbs/hugo/commands/html-proofer.yml | 8 ++ .../.circleci/orbs/hugo/jobs/build.yml | 34 ++++++ .../hugo-collapse/.circleci/orbs/hugo/orb.yml | 10 ++ .../.circleci/orbs/hugo/usage/build.yml | 8 ++ cmd/testdata/hugo-collapse/out.yml | 108 ++++++++++++++++++ 10 files changed, 217 insertions(+), 15 deletions(-) create mode 100644 cmd/testdata/hugo-collapse/.circleci/config.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/.DS_Store create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/README.md create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/build-hugo.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/html-proofer.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/jobs/build.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/orb.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/usage/build.yml create mode 100644 cmd/testdata/hugo-collapse/out.yml diff --git a/cmd/collapse_test.go b/cmd/collapse_test.go index bff835cec..736d7087e 100644 --- a/cmd/collapse_test.go +++ b/cmd/collapse_test.go @@ -41,26 +41,29 @@ var _ = Describe("collapse", func() { ).To(Succeed()) } }) + }) +}) + +var _ = Describe("collapse with testdata", func() { + var ( + command *exec.Cmd + results []byte + ) - It("collapse all YAML contents using directory structure as keys", func() { + Describe("a .circleci folder with config.yml and local orbs folder containing the hugo orb", 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") + 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(` -orbs: - one: - commands: - file: - contents_one: 1 - contents_two: 2 - two: - commands: - file: - contents_one: 1 - contents_two: 2 -`)) + Eventually(session.Out.Contents()).Should(MatchYAML(results)) Eventually(session).Should(gexec.Exit(0)) }) }) diff --git a/cmd/testdata/hugo-collapse/.circleci/config.yml b/cmd/testdata/hugo-collapse/.circleci/config.yml new file mode 100644 index 000000000..18ac24cb8 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/config.yml @@ -0,0 +1,4 @@ +workflows: + foo: + jobs: + - hugo/build diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/.DS_Store b/cmd/testdata/hugo-collapse/.circleci/orbs/.DS_Store new file mode 100644 index 000000000..e69de29bb diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/README.md b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/README.md new file mode 100644 index 000000000..a7fa997d9 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/README.md @@ -0,0 +1,3 @@ +# The hugo orb + +I'm just here to make sure we don't try to parse this markdown file as yaml. diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/build-hugo.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/build-hugo.yml new file mode 100644 index 000000000..49b875591 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/build-hugo.yml @@ -0,0 +1,24 @@ +description: "Runs the `hugo` CLI against a given source (default: current path) in a given env (default: production)" +parameters: + env: + description: "Passed in as the value of HUGO_ENV prior to running the hugo command" + type: string + default: "production" + source: + description: "a file path, relative to the root of your working directory, where your hugo root is. (passed as the value of the `-s` flag to hugo)" + type: string + default: "." + update-submodules: + description: "Boolean for whether to update git submodules." + type: boolean + default: false +steps: + - when: + condition: << parameters.update-submodules >> + steps: + - run: + name: "Get submodules to refresh themes" + command: git submodule update --init --recursive + - run: + name: "Build site with hugo" + command: HUGO_ENV=<< parameters.env >> hugo -v -s << parameters.source >> diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/html-proofer.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/html-proofer.yml new file mode 100644 index 000000000..9e6150fec --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/html-proofer.yml @@ -0,0 +1,8 @@ +parameters: + path: + type: string + description: "Path to the directory containing the published site, relative to the execution environment root." +steps: + - run: + name: "Run HTML Proofer to check for good html and such" + command: htmlproofer << parameters.path>> --allow-hash-href --check-html --empty-alt-ignore --disable-external diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/jobs/build.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/jobs/build.yml new file mode 100644 index 000000000..bdcde488a --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/jobs/build.yml @@ -0,0 +1,34 @@ +parameters: + source: + description: "a file path, relative to the root of your working directory, where your hugo root is. (passed as the value of the `-s` flag to hugo)" + default: "." + type: string + publishdir: + description: "Hugo sets the name of your publish Dir inside the site config, not as a CLI argument. Most people leave this to the default value of `public`, so that's what we do here. In most case you don't need to change this value." + default: "public" + type: string + html-proofer: + description: "Boolean value for whether to run the HTML Proofer. Set to `false` to stop the default behavior of running the proofer." + type: boolean + default: true + persist_to_workspace: + description: "Boolean value for whether to persist to a workspace drawing from the `parameters.source` as root and `parameters.publishdir` as the path." + type: boolean + default: true +executor: default +steps: + - checkout + - build-hugo: + source: "<< parameters.source >>" + - when: + condition: << parameters.html-proofer >> + steps: + - html-proofer: + - path: "<< parameters.source >>/<< parameters.publishdir >>" + - when: + condition: << parameters.persist_to_workspace >> + steps: + - persist_to_workspace: + root: "<< parameters.source >>" + paths: + - "<< parameters.publishdir >>" diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/orb.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/orb.yml new file mode 100644 index 000000000..d12c0a238 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/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 >> diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/usage/build.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/usage/build.yml new file mode 100644 index 000000000..a24a76e54 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/usage/build.yml @@ -0,0 +1,8 @@ +version: 2 +orbs: + hugo: circleci/hugo@latest + +workflows: + build-hugo: + jobs: + - hugo/build diff --git a/cmd/testdata/hugo-collapse/out.yml b/cmd/testdata/hugo-collapse/out.yml new file mode 100644 index 000000000..8994ccaeb --- /dev/null +++ b/cmd/testdata/hugo-collapse/out.yml @@ -0,0 +1,108 @@ +orbs: + hugo: + commands: + build-hugo: + description: 'Runs the `hugo` CLI against a given source (default: current + path) in a given env (default: production)' + parameters: + env: + default: production + description: Passed in as the value of HUGO_ENV prior to running the hugo + command + type: string + source: + default: . + description: a file path, relative to the root of your working directory, + where your hugo root is. (passed as the value of the `-s` flag to hugo) + type: string + update-submodules: + default: false + description: Boolean for whether to update git submodules. + type: boolean + steps: + - when: + condition: << parameters.update-submodules >> + steps: + - run: + command: git submodule update --init --recursive + name: Get submodules to refresh themes + - run: + command: HUGO_ENV=<< parameters.env >> hugo -v -s << parameters.source + >> + name: Build site with hugo + html-proofer: + parameters: + path: + description: Path to the directory containing the published site, relative + to the execution environment root. + type: string + steps: + - run: + command: htmlproofer << parameters.path>> --allow-hash-href --check-html + --empty-alt-ignore --disable-external + name: Run HTML Proofer to check for good html and such + 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 + jobs: + build: + executor: default + parameters: + html-proofer: + default: true + description: Boolean value for whether to run the HTML Proofer. Set to + `false` to stop the default behavior of running the proofer. + type: boolean + persist_to_workspace: + default: true + description: Boolean value for whether to persist to a workspace drawing + from the `parameters.source` as root and `parameters.publishdir` as + the path. + type: boolean + publishdir: + default: public + description: Hugo sets the name of your publish Dir inside the site config, + not as a CLI argument. Most people leave this to the default value of + `public`, so that's what we do here. In most case you don't need to + change this value. + type: string + source: + default: . + description: a file path, relative to the root of your working directory, + where your hugo root is. (passed as the value of the `-s` flag to hugo) + type: string + steps: + - checkout + - build-hugo: + source: << parameters.source >> + - when: + condition: << parameters.html-proofer >> + steps: + - html-proofer: null + - path: << parameters.source >>/<< parameters.publishdir >> + - when: + condition: << parameters.persist_to_workspace >> + steps: + - persist_to_workspace: + paths: + - << parameters.publishdir >> + root: << parameters.source >> + usage: + build: + orbs: + hugo: circleci/hugo@latest + version: 2 + workflows: + build-hugo: + jobs: + - hugo/build +workflows: + foo: + jobs: + - hugo/build