Skip to content

Commit

Permalink
Add testdata for integration testing collapse command with hugo orb
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Jun 22, 2018
1 parent 8d42f72 commit 998a258
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 15 deletions.
33 changes: 18 additions & 15 deletions cmd/collapse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})
Expand Down
4 changes: 4 additions & 0 deletions cmd/testdata/hugo-collapse/.circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
workflows:
foo:
jobs:
- hugo/build
Empty file.
3 changes: 3 additions & 0 deletions cmd/testdata/hugo-collapse/.circleci/orbs/hugo/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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 >>
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions cmd/testdata/hugo-collapse/.circleci/orbs/hugo/jobs/build.yml
Original file line number Diff line number Diff line change
@@ -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 >>"
10 changes: 10 additions & 0 deletions cmd/testdata/hugo-collapse/.circleci/orbs/hugo/orb.yml
Original file line number Diff line number Diff line change
@@ -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 >>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
orbs:
hugo: circleci/hugo@latest

workflows:
build-hugo:
jobs:
- hugo/build
108 changes: 108 additions & 0 deletions cmd/testdata/hugo-collapse/out.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 998a258

Please sign in to comment.