Skip to content

Commit

Permalink
Merge pull request #2 from CircleCI-Public/testdata
Browse files Browse the repository at this point in the history
Add testdata for integration testing collapse command
  • Loading branch information
Zachary Scott authored Jun 22, 2018
2 parents 2e6025c + dfe7531 commit 3c8a318
Show file tree
Hide file tree
Showing 46 changed files with 1,195 additions and 74 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
test:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/circleci/circleci-cli
working_directory: /go/src/github.com/CircleCI-Public/circleci-cli
steps:
- checkout
- run: make test
coverage:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/circleci/circleci-cli
working_directory: /go/src/github.com/CircleCI-Public/circleci-cli
steps:
- checkout
- run: make cover
Expand All @@ -52,7 +52,7 @@ jobs:
lint:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/circleci/circleci-cli
working_directory: /go/src/github.com/CircleCI-Public/circleci-cli
steps:
- checkout
- restore_cache:
Expand All @@ -74,7 +74,7 @@ jobs:
environment:
GORELEASER_URL: https://github.com/goreleaser/goreleaser/releases/download/v0.77.1/goreleaser_amd64.deb

working_directory: /go/src/github.com/circleci/circleci-cli
working_directory: /go/src/github.com/CircleCI-Public/circleci-cli
steps:
- checkout
- restore_cache:
Expand Down
33 changes: 32 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@ Second, it's written in Go. If you are new to Go, we recommend the following res
* [A Tour of Go](https://tour.golang.org/welcome/1)
* [The Go documentation](https://golang.org/doc/)

## Requirements

* Go 1.10+
* Make
* ...

## Getting setup

You should already have [installed Go](https://golang.org/doc/install) and setup your [workspace](https://golang.org/doc/code.html#Workspaces).

This includes setting a valid `$GOPATH`.

### 1. Get the repo

```
$ go get -u github.com/CircleCI-Public/circleci-cli
$ cd $GOPATH/src/github.com/CircleCI-Public/circleci-cli
```

### 2. Build the binary

```
$ make
```

### 3. Run tests

```
$ make test
```

## Managing Dependencies

We use `dep` for vendoring our depencencies:
Expand Down Expand Up @@ -80,4 +111,4 @@ You can view the documentation for this project in your browser using `godoc`.
After installing it via `make dev`.

1. Run `make doc`.
2. Access http://localhost:6060/pkg/github.com/circleci/circleci-cli/
2. Access http://localhost:6060/pkg/github.com/CircleCI-Public/circleci-cli/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GOFILES = $(shell find . -name '*.go' -not -path './vendor/*')

OS = $(shell uname)

CLIPATH=github.com/circleci/circleci-cli
CLIPATH=github.com/CircleCI-Public/circleci-cli

EXECUTABLE=circleci-cli
BUILD_DIR=build
Expand Down
34 changes: 8 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,24 @@

This project is the seed for CircleCI's new command-line application.

## Requirements

* Go 1.10+
* Make
* ...

## Getting Started

You should already have [installed Go](https://golang.org/doc/install) and setup your [workspace](https://golang.org/doc/code.html#Workspaces).

This includes setting a valid `$GOPATH`.

### 1. Get the repo

TODO: make this easier once repo is public
### 1. Get the latest binary

```
# Setup circleci source in your $GOPATH
$ mkdir -p $GOPATH/src/github.com/circleci
$ cd $GOPATH/src/github.com/circleci
# Clone the repo
$ git clone [email protected]/circleci/circleci-cli
$ cd circleci-cli
```
Download the [latest release](https://github.com/CircleCI-Public/circleci-cli/releases/latest) from GitHub for your operating system. If you're on a Mac, this would be `circleci-cli_0.1.X_darwin_amd64.tar.gz`.

### 2. Build the binary
### 2. Put the binary in your $PATH

```
$ make
$ tar -xvzf circleci-cli_0.1.X_darwin_amd64.tar.gz
$ mv circleci-beta /usr/local/bin
```

### 3. Run Diagnostic check
### 3. Run a Diagnostic check

```
$ ./build/target/darwin/amd64/circleci-cli diagnostic
$ circleci-beta diagnostic
Please enter your CircleCI API token:
OK.
Expand Down Expand Up @@ -88,7 +70,7 @@ fragment FullType on __Type {
You can now pipe that file to the `query` command to send it.

```
$ cat query.gql | ./build/target/darwin/amd64/circleci-cli query
$ cat query.gql | circleci-beta query
```

This should pretty-print back a JSON response from the server:
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
"context"

"github.com/circleci/circleci-cli/logger"
"github.com/CircleCI-Public/circleci-cli/logger"
"github.com/machinebox/graphql"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var pathCLI string

var _ = BeforeSuite(func() {
var err error
pathCLI, err = gexec.Build("github.com/circleci/circleci-cli")
pathCLI, err = gexec.Build("github.com/CircleCI-Public/circleci-cli")
Ω(err).ShouldNot(HaveOccurred())
})

Expand Down
2 changes: 1 addition & 1 deletion cmd/collapse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"regexp"

"github.com/circleci/circleci-cli/filetree"
"github.com/CircleCI-Public/circleci-cli/filetree"
"github.com/spf13/cobra"
yaml "gopkg.in/yaml.v2"
)
Expand Down
93 changes: 59 additions & 34 deletions cmd/collapse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd_test

import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"

Expand All @@ -13,54 +12,80 @@ import (

var _ = Describe("collapse", func() {
var (
tempRoot string
command *exec.Cmd
command *exec.Cmd
results []byte
)

BeforeEach(func() {
var err error
tempRoot, err = ioutil.TempDir("", "circleci-cli-test-")
Expect(err).ToNot(HaveOccurred())
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/result.yml")
Expect(err).ShouldNot(HaveOccurred())
})

command = exec.Command(pathCLI, "collapse", "-r", tempRoot)
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))
})
})

AfterEach(func() {
Expect(os.RemoveAll(tempRoot)).To(Succeed())
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())
})

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("with two YAML files within separate directory structures", func() {
Describe("an orb containing local executors and commands in folder", func() {
BeforeEach(func() {
for _, dirName := range []string{"one", "two"} {
path := filepath.Join(tempRoot, "orbs", dirName, "commands")
Expect(os.MkdirAll(path, 0700)).To(Succeed())
Expect(ioutil.WriteFile(
filepath.Join(path, "file.yml"),
[]byte("contents_one: 1\ncontents_two: 2\n"),
0600),
).To(Succeed())
}
var err error
command = exec.Command(pathCLI, "collapse", "-r", "testdata/myorb/test")
results, err = ioutil.ReadFile("testdata/myorb/result.yml")
Expect(err).ShouldNot(HaveOccurred())
})

It("collapse all YAML contents using directory structure as keys", func() {
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))
})
})

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
`))
Describe("with a large nested config including rails orb", func() {
BeforeEach(func() {
var err error
var path string = "test-with-large-nested-rails-orb"
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())
})

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))
})
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io/ioutil"
"os"

"github.com/circleci/circleci-cli/client"
"github.com/CircleCI-Public/circleci-cli/client"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"os"
"path"

"github.com/circleci/circleci-cli/logger"
"github.com/circleci/circleci-cli/settings"
"github.com/CircleCI-Public/circleci-cli/logger"
"github.com/CircleCI-Public/circleci-cli/settings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
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 >>"
Loading

0 comments on commit 3c8a318

Please sign in to comment.