diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e697ad5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +insert_final_newline = true +max_line_length = 160 +tab_width = 4 +trim_trailing_whitespace = true + +[Makefile] +indent_style = space + +[*.feature] +indent_style = space diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml new file mode 100644 index 0000000..254eeb9 --- /dev/null +++ b/.github/workflows/golangci-lint.yaml @@ -0,0 +1,38 @@ +name: lint +on: + push: + tags: + - v* + branches: + - master + - main + pull_request: +jobs: + golangci: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2.5.2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.42.0 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the action will use pre-installed Go. + # skip-go-installation: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..42456e3 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,60 @@ +name: test + +on: + push: + branches: + - master + pull_request: + +env: + GO111MODULE: "on" + GO_LATEST_VERSION: "1.17.x" + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest, macos-latest ] + go-version: [ 1.16.x, 1.17.x ] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Go cache + uses: actions/cache@v2 + with: + # In order: + # * Module download cache + # * Build cache (Linux) + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ matrix.go-version }}-cache-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ matrix.go-version }}-cache + + - name: Test + id: test + run: | + make test + + - name: Upload code coverage (unit) + if: matrix.go-version == env.GO_LATEST_VERSION + uses: codecov/codecov-action@v1 + with: + file: ./unit.coverprofile + flags: unittests-${{ runner.os }} + + - name: Upload code coverage (features) + if: matrix.go-version == env.GO_LATEST_VERSION + uses: codecov/codecov-action@v1 + with: + file: ./features.coverprofile + flags: featurestests-${{ runner.os }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..04bd755 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +/vendor + +*.coverprofile diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..79af0b0 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,49 @@ +# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml +run: + tests: true + +linters-settings: + errcheck: + check-type-assertions: true + check-blank: true + gocyclo: + min-complexity: 20 + dupl: + threshold: 100 + misspell: + locale: US + unused: + check-exported: false + unparam: + check-exported: true + +linters: + enable-all: true + disable: + - exhaustivestruct + - forbidigo + - forcetypeassert + - gci + - gochecknoglobals + - golint + - gomnd + - ifshort + - interfacer + - lll + - maligned + - paralleltest + - scopelint + - testpackage + - wrapcheck + +issues: + exclude-use-default: false + exclude-rules: + - linters: + - dupl + - funlen + - goconst + - goerr113 + - gomnd + - noctx + path: "_test.go" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ae795b9 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +VENDOR_DIR = vendor + +GO ?= go +GOLANGCI_LINT ?= golangci-lint + +.PHONY: $(VENDOR_DIR) lint test test-unit test-integration + +$(VENDOR_DIR): + @mkdir -p $(VENDOR_DIR) + @$(GO) mod vendor + @$(GO) mod tidy + +lint: + @$(GOLANGCI_LINT) run + +test: test-unit test-integration + +## Run unit tests +test-unit: + @echo ">> unit test" + @$(GO) test -gcflags=-l -coverprofile=unit.coverprofile -covermode=atomic -race ./... + +test-integration: + @echo ">> integration test" + @$(GO) test ./features/... -gcflags=-l -coverprofile=features.coverprofile -coverpkg ./... -godog -race diff --git a/README.md b/README.md new file mode 100644 index 0000000..916929e --- /dev/null +++ b/README.md @@ -0,0 +1,431 @@ +# Afero Cucumber Steps for Golang + +[![GitHub Releases](https://img.shields.io/github/v/release/godogx/aferosteps)](https://github.com/godogx/aferosteps/releases/latest) +[![Build Status](https://github.com/godogx/aferosteps/actions/workflows/test.yaml/badge.svg)](https://github.com/godogx/aferosteps/actions/workflows/test.yaml) +[![codecov](https://codecov.io/gh/godogx/aferosteps/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/godogx/aferosteps) +[![Go Report Card](https://goreportcard.com/badge/github.com/godogx/aferosteps)](https://goreportcard.com/report/github.com/godogx/aferosteps) +[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/godogx/aferosteps) + +Interacting with multiple filesystems in [`cucumber/godog`](https://github.com/cucumber/godog) with [spf13/afero](https://github.com/spf13/afero) + +## Prerequisites + +- `Go >= 1.16` + +## Install + +```bash +go get github.com/godogx/aferosteps +``` + +## Usage + +Initiate a new FS Manager with `aferosteps.NewManager` then add it to `ScenarioInitializer` by +calling `Manager.RegisterContext(*testing.T, *godog.ScenarioContext)` + +The `Manager` supports multiple file systems and by default, it uses `afero.NewOsFs()`. If you wish to: + +- Change the default fs, use `aferosteps.WithDefaultFs(fs afero.Fs)` in the constructor. +- Add more fs, use `aferosteps.WithFs(name string, fs afero.Fs)` in the constructor. + +For example: + +```go +package mypackage + +import ( + "math/rand" + "testing" + + "github.com/cucumber/godog" + "github.com/godogx/aferosteps" + "github.com/spf13/afero" + "github.com/stretchr/testify/require" +) + +func TestIntegration(t *testing.T) { + fsManager := aferosteps.NewManager( + aferosteps.WithFs("mem", afero.NewMemMapFs()), + ) + + suite := godog.TestSuite{ + Name: "Integration", + ScenarioInitializer: func(ctx *godog.ScenarioContext) { + fsManager.RegisterContext(t, ctx) + }, + Options: &godog.Options{ + Strict: true, + Randomize: rand.Int63(), + }, + } + + // Run the suite. +} +``` + +Note: the `Manager` will reset the working directory at the beginning of the scenario to the one when the test starts. + +## Steps + +### Change to a temporary directory + +Change to a temporary directory provided by calling [`t.(*testing.T).TempDir()`](https://golang.org/pkg/testing/#B.TempDir) + +Pattern: `(?:current|working) directory is temporary` + +Example: + +```gherkin +Feature: OS FS + + Background: + Given current directory is temporary + And there is a directory "test" +``` + +### Change working directory + +Change to a directory of your choice. + +Pattern: + +- `(?:current|working) directory is "([^"]+)"` +- `changes? (?:current|working) directory to "([^"]+)"` + +```gherkin +Feature: OS FS + + Scenario: .github equal + When I reset current directory + And I change current directory to "../../.github" + + Then there should be only these files: + """ + - workflows: + - golangci-lint.yaml + - test.yaml + """ + + Scenario: .github equal with cwd + When I reset current directory + And current directory is "../../.github" + + Then there should be only these files: + """ + - workflows: + - golangci-lint.yaml + - test.yaml + """ +``` + +### Reset working directory + +Reset the working directory to the one when the test starts. + +Pattern: `resets? (?:current|working) directory` + +```gherkin +Feature: OS FS + + Scenario: .github equal + When I reset current directory + And I change current directory to "../../.github" + + Then there should be only these files: + """ + - workflows: + - golangci-lint.yaml + - test.yaml + """ +``` + +### Remove a file + +Remove a file from a fs. + +Pattern: + +- With the default fs: `^there is no (?:file|directory) "([^"]+)"$` +- With a fs at your choice: `^there is no (?:file|directory) "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)$` + +```gherkin +Feature: Mixed + + Background: + Given there is no file "test/file1.txt" + And there is no file "test/file1.txt" in "mem" fs +``` + +### Create a file + +#### Empty file + +Pattern: + +- With the default fs: `^there is a file "([^"]+)"$` +- With a fs at your choice: `^there is a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)$` + +```gherkin +Feature: Mixed + + Background: + Given there is a file "test/file1.txt" + And there is a file "test/file1.txt" in "mem" fs +``` + +#### With Content + +Pattern: + +- With the default fs: `^there is a file "([^"]+)" with content:` +- With a fs at your choice: `^there is a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system) with content:` + +```gherkin +Feature: Mixed + + Background: + Given there is a file "test/file2.sh" with content: + """ + #!/usr/bin/env bash + + echo "hello" + """ + + And there is a file "test/file2.sh" in "mem" fs with content: + """ + #!/usr/bin/env bash + + echo "hello" + """ +``` + +### Create a directory + +Pattern: + +- With the default fs: `^there is a directory "([^"]+)"$` +- With a fs at your choice: `^there is a directory "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)` + +```gherkin +Feature: Mixed + + Background: + Given there is a directory "test" + And there is a directory "test" in "mem" fs +``` + +### Change file or directory permission + +Pattern: + +- With the default fs: + - `changes? "([^"]+)" permission to ([0-9]+)$` + - `^(?:file|directory) "([^"]+)" permission is ([0-9]+)$` +- With a fs at your choice: + - `changes? "([^"]+)" permission in "([^"]+)" (?:fs|filesystem|file system) to ([0-9]+)` + - `^(?:file|directory) "([^"]+)" permission in "([^"]+)" (?:fs|filesystem|file system) is ([0-9]+)` + +```gherkin +Feature: Mixed + + Background: + Given file "test/file1.txt" permission is 0644 + And file "test/file1.txt" permission in "mem" fs is 0644 + And I change "test/file2.sh" permission to 0755 + And I change "test/file2.sh" permission in "mem" fs to 0755 +``` + +### Assert file exists + +Pattern: + +- With the default fs: `^there should be a file "([^"]+)"$` +- With a fs at your choice: `^there should be a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)` + +```gherkin +Feature: Mixed + + Background: + Given there should be a file "test/file1.txt" + And there should be a file "test/file1.txt" in "mem" fs +``` + +### Assert directory exists + +Pattern: + +- With the default fs: `^there should be a directory "([^"]+)"$` +- With a fs at your choice: `^there should be a directory "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)$` + +```gherkin +Feature: Mixed + + Background: + Given there should be a directory "test" + And there should be a directory "test" in "mem" fs +``` + +### Assert file content + +#### Plain Text + +Pattern: + +- With the default fs: `^there should be a file "([^"]+)" with content:` +- With a fs at your choice: `^there should be a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system) with content:` + +```gherkin +Feature: Mixed + + Background: + Given there should be a file "test/file2.sh" with content: + """ + #!/usr/bin/env bash + + echo "hello" + """ + + And there should be a file "test/file2.sh" in "mem" fs with content: + """ + #!/usr/bin/env bash + + echo "hello" + """ +``` + +#### Regexp + +Pattern: + +- With the default fs: `^there should be a file "([^"]+)" with content matches:` +- With a fs at your choice: `^there should be a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system) with content matches:` + +```gherkin +Feature: Mixed + + Background: + Given there should be a file "test/file2.sh" with content matches: + """ + #!/usr/bin/env bash + + echo "" + """ + + And there should be a file "test/file2.sh" in "mem" fs with content matches: + """ + #!/usr/bin/env bash + + echo "" + """ +``` + +### Assert file permission + +Pattern: + +- With the default fs: `^(?:file|directory) "([^"]+)" permission should be ([0-9]+)$` +- With a fs at your choice: `^(?:file|directory) "([^"]+)" permission in "([^"]+)" (?:fs|filesystem|file system) should be ([0-9]+)` + +```gherkin +Feature: Mixed + + Background: + Given directory "test" permission should be 0755 + And file "test/file2.sh" permission should be 0755 + And directory "test" permission in "mem" fs should be 0755 + And file "test/file2.sh" permission in "mem" fs should be 0755 +``` + +### Assert file tree + +#### Exact tree + +Check whether the file tree is exactly the same as the expectation. + +Pattern: + +- With the current working directory: + - With the default fs: `^there should be only these files:` + - With a fs at your choice: `^there should be only these files in "([^"]+)" (?:fs|filesystem|file system):` +- With a path: + - With the default fs: `^there should be only these files in "([^"]+)":` + - With a fs at your choice: `^there should be only these files in "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system):` + +```gherkin +Feature: Mixed + + Scenario: OS FS + And there should be only these files: + """ + - test 'perm:"0755"': + - file1.txt 'perm:"0644"' + - file2.sh 'perm:"0755"' + """ + + Scenario: Memory FS + Then there should be only these files in "mem" fs: + """ + - test 'perm:"0755"': + - file1.txt + - file2.sh 'perm:"0755"' + """ +``` + +#### Contains + +Check whether the file tree contains the expectation. + +Pattern: + +- With the current working directory: + - With the default fs: `^there should be these files:` + - With a fs at your choice: `^there should be these files in "([^"]+)" (?:fs|filesystem|file system):` +- With a path: + - With the default fs: `^there should be these files in "([^"]+)":` + - With a fs at your choice: `^there should be these files in "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system):` + +```gherkin +Feature: Mixed + + Scenario: OS FS + And there should be these files: + """ + - test 'perm:"0755"': + - file1.txt 'perm:"0644"' + - file2.sh 'perm:"0755"' + """ + + Scenario: Memory FS + Then there should be these files in "mem" fs: + """ + - test 'perm:"0755"': + - file1.txt + - file2.sh 'perm:"0755"' + """ +``` + +## Variables + +You can use these variables in your steps: + +Variable | Description +:--- | :--- +`$TEST_DIR` | The working directory where tests start +`$CWD` | Current working directory, get from `os.Getwd()` +`$WOKRING_DIR` | Same as `$CWD` + +For examples: + +```gherkin + Scenario: .github equal in path + Then there should be only these files in "$TEST_DIR/../../.github": + """ + - workflows: + - golangci-lint.yaml + - test.yaml + """ +``` + +## Examples + +Full suite: https://github.com/godogx/aferosteps/tree/master/features diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..70917de --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +ignore: + - "features/**/*" diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..42dd988 --- /dev/null +++ b/doc.go @@ -0,0 +1,2 @@ +// Package aferosteps provides cucumber steps. +package aferosteps diff --git a/features/bootstrap/godog_test.go b/features/bootstrap/godog_test.go new file mode 100644 index 0000000..e3d9c56 --- /dev/null +++ b/features/bootstrap/godog_test.go @@ -0,0 +1,91 @@ +package bootstrap + +import ( + "bytes" + "flag" + "fmt" + "io/ioutil" + "path/filepath" + "strings" + "testing" + + "github.com/cucumber/godog" + "github.com/spf13/afero" + "github.com/stretchr/testify/assert" + + "github.com/godogx/aferosteps" +) + +// Used by init(). +// +//nolint:gochecknoglobals +var ( + runGoDogTests bool + + out = new(bytes.Buffer) + opt = godog.Options{ + Strict: true, + Output: out, + } +) + +// This has to run on init to define -godog flag, otherwise "undefined flag" error happens. +// +//nolint:gochecknoinits +func init() { + flag.BoolVar(&runGoDogTests, "godog", false, "Set this flag is you want to run godog BDD tests") + godog.BindFlags("godog.", flag.CommandLine, &opt) // nolint: staticcheck +} + +func TestIntegration(t *testing.T) { + if !runGoDogTests { + t.Skip(`Missing "--godog" flag, skipping integration test.`) + } + + fsManager := aferosteps.NewManager( + aferosteps.WithFs("mem", afero.NewMemMapFs()), + ) + + RunSuite(t, "..", func(_ *testing.T, ctx *godog.ScenarioContext) { + fsManager.RegisterContext(t, ctx) + }) +} + +func RunSuite(t *testing.T, path string, featureContext func(t *testing.T, ctx *godog.ScenarioContext)) { + t.Helper() + + var paths []string + + files, err := ioutil.ReadDir(filepath.Clean(path)) + assert.NoError(t, err) + + paths = make([]string, 0, len(files)) + + for _, f := range files { + if strings.HasSuffix(f.Name(), ".feature") { + paths = append(paths, filepath.Join(path, f.Name())) + } + } + + for _, path := range paths { + path := path + + t.Run(path, func(t *testing.T) { + opt.Paths = []string{path} + suite := godog.TestSuite{ + Name: "Integration", + TestSuiteInitializer: nil, + ScenarioInitializer: func(s *godog.ScenarioContext) { + featureContext(t, s) + }, + Options: &opt, + } + status := suite.Run() + + if status != 0 { + fmt.Println(out.String()) + assert.Fail(t, "one or more scenarios failed in feature: "+path) + } + }) + } +} diff --git a/features/mem.feature b/features/mem.feature new file mode 100644 index 0000000..e732014 --- /dev/null +++ b/features/mem.feature @@ -0,0 +1,64 @@ +Feature: Memory FS + + Background: + Given there is a directory "test" in "mem" fs + And there is a file "test/file1.txt" in "mem" fs + And there is a file "test/file2.sh" in "mem" fs with content: + """ + #!/usr/bin/env bash + + echo "hello" + """ + + And file "test/file1.txt" permission in "mem" fs is 0644 + And I change "test/file2.sh" permission in "mem" fs to 0755 + + Scenario: Basic Assertions + Then there should be a directory "test" in "mem" fs + And there should be a file "test/file1.txt" in "mem" fs + And there should be a file "test/file2.sh" in "mem" fs with content: + """ + #!/usr/bin/env bash + + echo "hello" + """ + + And directory "test" permission in "mem" fs should be 0755 + And file "test/file1.txt" permission in "mem" fs should be 0644 + And file "test/file2.sh" permission in "mem" fs should be 0755 + + Scenario: Regexp Assertions + And there should be a file "test/file2.sh" in "mem" fs with content matches: + """ + #!/usr/bin/env bash + + echo "" + """ + + Scenario: Tree Contains + Then there should be these files in "mem" fs: + """ + - test 'perm:"0755"': + - file1.txt + - file2.sh 'perm:"0755"' + """ + + And there should be these files in "test/" in "mem" fs: + """ + - file1.txt + - file2.sh 'perm:"0755"' + """ + + Scenario: Tree Equal + Then there should be only these files in "mem" fs: + """ + - test 'perm:"0755"': + - file1.txt + - file2.sh 'perm:"0755"' + """ + + And there should be only these files in "test/" in "mem" fs: + """ + - file1.txt + - file2.sh 'perm:"0755"' + """ diff --git a/features/os.feature b/features/os.feature new file mode 100644 index 0000000..637cddd --- /dev/null +++ b/features/os.feature @@ -0,0 +1,129 @@ +Feature: OS FS + + Background: + Given current directory is temporary + And there is a directory "test" + And there is a file "test/file1.txt" + And there is a file "test/file2.sh" with content: + """ + #!/usr/bin/env bash + + echo "hello" + """ + + And file "test/file1.txt" permission is 0644 + And I change "test/file2.sh" permission to 0755 + + Scenario: Basic Assertions + Then there should be a directory "test" + And there should be a file "test/file1.txt" + And there should be a file "test/file2.sh" with content: + """ + #!/usr/bin/env bash + + echo "hello" + """ + + And directory "test" permission should be 0755 + And file "test/file1.txt" permission should be 0644 + And file "test/file2.sh" permission should be 0755 + + Scenario: Regexp Assertions + And there should be a file "test/file2.sh" with content matches: + """ + #!/usr/bin/env bash + + echo "" + """ + + Scenario: Tree Contains + And there should be these files: + """ + - test 'perm:"0755"': + - file1.txt 'perm:"0644"' + - file2.sh 'perm:"0755"' + """ + + Scenario: Tree Equal + And there should be only these files: + """ + - test 'perm:"0755"': + - file1.txt 'perm:"0644"' + - file2.sh 'perm:"0755"' + """ + + Scenario: .github contains + When I reset current directory + And I change current directory to "../.." + + Then there should be these files: + """ + - .github: + - workflows: + - golangci-lint.yaml + - test.yaml + """ + + Scenario: .github contains with cwd + When I reset current directory + And current directory is "../.." + + Then there should be these files: + """ + - .github: + - workflows: + - golangci-lint.yaml + - test.yaml + """ + + Scenario: .github contains in path + When I reset current directory + + Then there should be these files in "../..": + """ + - .github: + - workflows: + - golangci-lint.yaml + - test.yaml + """ + + Scenario: .github contains in path + When I reset current directory + + Then there should be these files in "../..": + """ + - .github: + - workflows: + - golangci-lint.yaml + - test.yaml + """ + + Scenario: .github equal + When I reset current directory + And I change current directory to "../../.github" + + Then there should be only these files: + """ + - workflows: + - golangci-lint.yaml + - test.yaml + """ + + Scenario: .github equal with cwd + When I reset current directory + And current directory is "../../.github" + + Then there should be only these files: + """ + - workflows: + - golangci-lint.yaml + - test.yaml + """ + + Scenario: .github equal in path + Then there should be only these files in "$TEST_DIR/../../.github": + """ + - workflows: + - golangci-lint.yaml + - test.yaml + """ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b070c7d --- /dev/null +++ b/go.mod @@ -0,0 +1,28 @@ +module github.com/godogx/aferosteps + +go 1.17 + +require ( + github.com/cucumber/godog v0.12.1 + github.com/godogx/expandvars v0.1.0 + github.com/nhatthm/aferoassert v0.1.5 + github.com/nhatthm/aferomock v0.3.0 + github.com/spf13/afero v1.6.0 + github.com/stretchr/testify v1.7.0 +) + +require ( + github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect + github.com/cucumber/messages-go/v16 v16.0.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fatih/structtag v1.2.0 // indirect + github.com/gofrs/uuid v4.0.0+incompatible // indirect + github.com/hashicorp/go-immutable-radix v1.3.1 // indirect + github.com/hashicorp/go-memdb v1.3.2 // indirect + github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/stretchr/objx v0.3.0 // indirect + golang.org/x/text v0.3.6 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..cd70058 --- /dev/null +++ b/go.sum @@ -0,0 +1,341 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cucumber/gherkin-go/v19 v19.0.3 h1:mMSKu1077ffLbTJULUfM5HPokgeBcIGboyeNUof1MdE= +github.com/cucumber/gherkin-go/v19 v19.0.3/go.mod h1:jY/NP6jUtRSArQQJ5h1FXOUgk5fZK24qtE7vKi776Vw= +github.com/cucumber/godog v0.12.1 h1:IhWVYFKDReM5WsuA9AuRLRPWOyvFNO9UBUKrNfLPais= +github.com/cucumber/godog v0.12.1/go.mod h1:u6SD7IXC49dLpPN35kal0oYEjsXZWee4pW6Tm9t5pIc= +github.com/cucumber/messages-go/v16 v16.0.0/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= +github.com/cucumber/messages-go/v16 v16.0.1 h1:fvkpwsLgnIm0qugftrw2YwNlio+ABe2Iu94Ap8GMYIY= +github.com/cucumber/messages-go/v16 v16.0.1/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= +github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/godogx/expandvars v0.1.0 h1:msk+LqBDgtckUIwn37mhE4e+k7n+44wZZN8BpFTYWMI= +github.com/godogx/expandvars v0.1.0/go.mod h1:50+yWZ9Z9ueaisxOQz4AwaLjzf0XwdcEHYcIB/JYdrc= +github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= +github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= +github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-memdb v1.3.0/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g= +github.com/hashicorp/go-memdb v1.3.2 h1:RBKHOsnSszpU6vxq80LzC2BaQjuuvoyaQbkLTf7V7g8= +github.com/hashicorp/go-memdb v1.3.2/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE= +github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/nhatthm/aferoassert v0.1.5 h1:5BKwmRUpthkJpEPUPtcMHN37mdpFbYCECCJWhI/opRU= +github.com/nhatthm/aferoassert v0.1.5/go.mod h1:l5NAuwTqiLY2vXnNbi61wE9YkEu3L9SaTNmcRyMzn2Y= +github.com/nhatthm/aferomock v0.3.0 h1:VaQORa7jawxeTi7yAAayE8ZUo7lYp5yyDn9j3wwKJNA= +github.com/nhatthm/aferomock v0.3.0/go.mod h1:/oTcy0NDM+qQJEEOWiuiKuogilXvv/KZcdaXaP/rX3g= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= +github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As= +github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/manager.go b/manager.go new file mode 100644 index 0000000..93d3cf0 --- /dev/null +++ b/manager.go @@ -0,0 +1,434 @@ +package aferosteps + +import ( + "context" + "fmt" + "os" + "path/filepath" + "sync" + + "github.com/cucumber/godog" + "github.com/godogx/expandvars" + "github.com/nhatthm/aferoassert" + "github.com/spf13/afero" +) + +const defaultFs = "_default" + +// TempDirer creates a temp dir evey time it is called. +type TempDirer interface { + TempDir() string +} + +// Option is to configure Manager. +type Option func(m *Manager) + +// Manager manages a list of file systems and provides steps for godog. +type Manager struct { + td TempDirer + + fss map[string]afero.Fs + testDir string + trackedFiles map[string][]string + + mu sync.Mutex +} + +func (m *Manager) registerExpander(ctx *godog.ScenarioContext) { + expandvars.NewStepExpander( + func() expandvars.Pairs { + cwd, err := os.Getwd() + mustNoError(err) + + return expandvars.Pairs{ + "TEST_DIR": m.testDir, + "CWD": cwd, + "WORKING_DIR": cwd, + } + }, + ).RegisterExpander(ctx) +} + +// RegisterContext registers all the steps. +func (m *Manager) RegisterContext(td TempDirer, ctx *godog.ScenarioContext) { + m.registerExpander(ctx) + + ctx.Before(func(context.Context, *godog.Scenario) (context.Context, error) { + m.WithTempDirer(td) + _ = m.resetDir() // nolint: errcheck + + return nil, nil + }) + + ctx.After(func(context.Context, *godog.Scenario, error) (context.Context, error) { + m.cleanup() + _ = m.resetDir() // nolint: errcheck + + return nil, nil + }) + + // Utils. + ctx.Step(`(?:current|working) directory is temporary`, m.chTempDir) + ctx.Step(`(?:current|working) directory is "([^"]+)"`, m.chDir) + ctx.Step(`changes? (?:current|working) directory to "([^"]+)"`, m.chDir) + ctx.Step(`resets? (?:current|working) directory`, m.resetDir) + + // Default FS. + ctx.Step(`^there is no (?:file|directory) "([^"]+)"$`, m.removeFile) + ctx.Step(`^there is a file "([^"]+)"$`, m.createFile) + ctx.Step(`^there is a directory "([^"]+)"$`, m.createDirectory) + ctx.Step(`^there is a file "([^"]+)" with content:`, m.createFileWithContent) + ctx.Step(`changes? "([^"]+)" permission to ([0-9]+)$`, m.chmod) + ctx.Step(`^(?:file|directory) "([^"]+)" permission is ([0-9]+)$`, m.chmod) + + ctx.Step(`^there should be a file "([^"]+)"$`, m.assertFileExists) + ctx.Step(`^there should be a directory "([^"]+)"$`, m.assertDirectoryExists) + ctx.Step(`^there should be a file "([^"]+)" with content:`, m.assertFileContent) + ctx.Step(`^there should be a file "([^"]+)" with content matches:`, m.assertFileContentRegexp) + ctx.Step(`^(?:file|directory) "([^"]+)" permission should be ([0-9]+)$`, m.assertFilePerm) + ctx.Step(`^there should be only these files:`, m.assertTreeEqual) + ctx.Step(`^there should be these files:`, m.assertTreeContains) + ctx.Step(`^there should be only these files in "([^"]+)":`, m.assertTreeEqualInPath) + ctx.Step(`^there should be these files in "([^"]+)":`, m.assertTreeContainsInPath) + + // Another FS. + ctx.Step(`^there is no (?:file|directory) "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)$`, m.removeFileInFs) + ctx.Step(`^there is a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)$`, m.createFileInFs) + ctx.Step(`^there is a directory "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)$`, m.createDirectoryInFs) + ctx.Step(`^there is a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system) with content:`, m.createFileInFsWithContent) + ctx.Step(`changes? "([^"]+)" permission in "([^"]+)" (?:fs|filesystem|file system) to ([0-9]+)$`, m.chmodInFs) + ctx.Step(`^(?:file|directory) "([^"]+)" permission in "([^"]+)" (?:fs|filesystem|file system) is ([0-9]+)$`, m.chmodInFs) + + ctx.Step(`^there should be a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)$`, m.assertFileExistsInFs) + ctx.Step(`^there should be a directory "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system)$`, m.assertDirectoryExistsInFs) + ctx.Step(`^there should be a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system) with content:`, m.assertFileContentInFs) + ctx.Step(`^there should be a file "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system) with content matches:`, m.assertFileContentRegexpInFs) + ctx.Step(`^(?:file|directory) "([^"]+)" permission in "([^"]+)" (?:fs|filesystem|file system) should be ([0-9]+)$`, m.assertFilePermInFs) + ctx.Step(`^there should be only these files in "([^"]+)" (?:fs|filesystem|file system):`, m.assertTreeEqualInFs) + ctx.Step(`^there should be these files in "([^"]+)" (?:fs|filesystem|file system):`, m.assertTreeContainsInFs) + ctx.Step(`^there should be only these files in "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system):`, m.assertTreeEqualInPathInFs) + ctx.Step(`^there should be these files in "([^"]+)" in "([^"]+)" (?:fs|filesystem|file system):`, m.assertTreeContainsInPathInFs) +} + +// WithTempDirer sets the TempDirer. +func (m *Manager) WithTempDirer(td TempDirer) *Manager { + m.mu.Lock() + defer m.mu.Unlock() + + m.td = td + + return m +} + +func (m *Manager) cleanup() { + for id, files := range m.trackedFiles { + fs := m.fs(id) + + for _, f := range files { + _ = fs.RemoveAll(f) // nolint: errcheck + } + } + + m.mu.Lock() + defer m.mu.Unlock() + + m.trackedFiles = make(map[string][]string) +} + +func (m *Manager) trackPath(fs afero.Fs, path string) (string, error) { + parent := filepath.Dir(path) + + if parent != "." { + track, err := m.trackPath(fs, parent) + if err != nil { + return "", err + } + + if track != "" { + return track, nil + } + } + + if _, err := fs.Stat(path); err != nil { + if os.IsNotExist(err) { + return path, nil + } + + return "", fmt.Errorf("could not stat(%q): %w", path, err) + } + + return "", nil +} + +func (m *Manager) track(fs string, path string) error { + if _, ok := m.trackedFiles[fs]; !ok { + m.trackedFiles[fs] = make([]string, 0) + } + + path, err := m.trackPath(m.fs(fs), filepath.Clean(path)) + if err != nil { + return err + } + + if path == "" { + return nil + } + + m.trackedFiles[fs] = append(m.trackedFiles[fs], path) + + return nil +} + +func (m *Manager) fs(name string) afero.Fs { + m.mu.Lock() + defer m.mu.Unlock() + + return m.fss[name] +} + +func (m *Manager) chTempDir() error { + // TempDir will be deleted automatically, we don't need to track it manually. + return m.chDir(m.td.TempDir()) +} + +func (m *Manager) chDir(dir string) error { + return os.Chdir(dir) +} + +func (m *Manager) resetDir() error { + return m.chDir(m.testDir) +} + +func (m *Manager) chmod(path, perm string) error { + return m.chmodInFs(path, defaultFs, perm) +} + +func (m *Manager) removeFile(path string) error { + return m.removeFileInFs(path, defaultFs) +} + +func (m *Manager) createFile(path string) error { + return m.createFileInFs(path, defaultFs) +} + +func (m *Manager) createDirectory(path string) error { + return m.createDirectoryInFs(path, defaultFs) +} + +func (m *Manager) createFileWithContent(path string, body *godog.DocString) error { + return m.createFileInFsWithContent(path, defaultFs, body) +} + +func (m *Manager) assertFileExists(path string) error { + return m.assertFileExistsInFs(path, defaultFs) +} + +func (m *Manager) assertDirectoryExists(path string) error { + return m.assertDirectoryExistsInFs(path, defaultFs) +} + +func (m *Manager) assertFileContent(path string, body *godog.DocString) error { + return m.assertFileContentInFs(path, defaultFs, body) +} + +func (m *Manager) assertFileContentRegexp(path string, body *godog.DocString) error { + return m.assertFileContentRegexpInFs(path, defaultFs, body) +} + +func (m *Manager) assertFilePerm(path string, perm string) error { + return m.assertFilePermInFs(path, defaultFs, perm) +} + +func (m *Manager) assertTreeEqual(body *godog.DocString) error { + return m.assertTreeEqualInFs(defaultFs, body) +} + +func (m *Manager) assertTreeEqualInPath(path string, body *godog.DocString) error { + return m.assertTreeEqualInPathInFs(path, defaultFs, body) +} + +func (m *Manager) assertTreeContains(body *godog.DocString) error { + return m.assertTreeContainsInFs(defaultFs, body) +} + +func (m *Manager) assertTreeContainsInPath(path string, body *godog.DocString) error { + return m.assertTreeContainsInPathInFs(path, defaultFs, body) +} + +func (m *Manager) chmodInFs(path string, fs string, permStr string) error { + perm, err := strToPerm(permStr) + if err != nil { + return err + } + + return m.fs(fs).Chmod(path, perm) +} + +func (m *Manager) removeFileInFs(path, fs string) error { + return m.fs(fs).RemoveAll(path) +} + +func (m *Manager) createFileInFs(path, fs string) error { + return m.createFileInFsWithContent(path, fs, nil) +} + +func (m *Manager) createDirectoryInFs(path, fs string) error { + if err := m.track(fs, path); err != nil { + return fmt.Errorf("could not track directory: %w", err) + } + + path = filepath.Clean(path) + + if err := m.fs(fs).MkdirAll(path, 0o755); err != nil { + return fmt.Errorf("could not mkdir %q: %w", path, err) + } + + return nil +} + +func (m *Manager) createFileInFsWithContent(path, fsID string, body *godog.DocString) error { + if err := m.track(fsID, path); err != nil { + return fmt.Errorf("could not track file: %w", err) + } + + fs := m.fs(fsID) + parent := filepath.Dir(path) + + if err := fs.MkdirAll(parent, 0o755); err != nil { + return fmt.Errorf("could not mkdir %q: %w", parent, err) + } + + path = filepath.Clean(path) + + f, err := fs.Create(path) + if err != nil { + return fmt.Errorf("could not create %q: %w", path, err) + } + + defer f.Close() // nolint: errcheck + + if body != nil { + if _, err = f.WriteString(body.Content); err != nil { + return fmt.Errorf("could not write file %q: %w", path, err) + } + } + + return nil +} + +func (m *Manager) assertFileExistsInFs(path string, fs string) error { + t := teeError() + + if !aferoassert.FileExists(t, m.fs(fs), path) { + return t.LastError() + } + + return nil +} + +func (m *Manager) assertDirectoryExistsInFs(path string, fs string) error { + t := teeError() + + if !aferoassert.DirExists(t, m.fs(fs), path) { + return t.LastError() + } + + return nil +} + +func (m *Manager) assertFileContentInFs(path string, fs string, body *godog.DocString) error { + t := teeError() + + if !aferoassert.FileContent(t, m.fs(fs), path, body.Content) { + return t.LastError() + } + + return nil +} + +func (m *Manager) assertFileContentRegexpInFs(path string, fs string, body *godog.DocString) error { + t := teeError() + + if !aferoassert.FileContentRegexp(t, m.fs(fs), path, fileContentRegexp(body.Content)) { + return t.LastError() + } + + return nil +} + +func (m *Manager) assertFilePermInFs(path string, fs string, permStr string) error { + perm, err := strToPerm(permStr) + if err != nil { + return err + } + + t := teeError() + + if !aferoassert.Perm(t, m.fs(fs), path, perm) { + return t.LastError() + } + + return nil +} + +func (m *Manager) assertTreeEqualInFs(fs string, body *godog.DocString) error { + return m.assertTreeEqualInPathInFs("", fs, body) +} + +func (m *Manager) assertTreeEqualInPathInFs(path, fs string, body *godog.DocString) error { + t := teeError() + + if !aferoassert.YAMLTreeEqual(t, m.fs(fs), body.Content, path) { + return t.LastError() + } + + return nil +} + +func (m *Manager) assertTreeContainsInFs(fs string, body *godog.DocString) error { + return m.assertTreeContainsInPathInFs("", fs, body) +} + +func (m *Manager) assertTreeContainsInPathInFs(path, fs string, body *godog.DocString) error { + t := teeError() + + if !aferoassert.YAMLTreeContains(t, m.fs(fs), body.Content, path) { + return t.LastError() + } + + return nil +} + +// NewManager initiates a new Manager. +func NewManager(options ...Option) *Manager { + cwd, err := os.Getwd() + mustNoError(err) + + m := &Manager{ + fss: map[string]afero.Fs{ + defaultFs: afero.NewOsFs(), + }, + testDir: cwd, + trackedFiles: make(map[string][]string), + } + + for _, o := range options { + o(m) + } + + return m +} + +// WithFs sets a file system by name. +func WithFs(name string, fs afero.Fs) Option { + return func(m *Manager) { + m.fss[name] = fs + } +} + +// WithDefaultFs sets the default file system. +func WithDefaultFs(fs afero.Fs) Option { + return func(m *Manager) { + m.fss[defaultFs] = fs + } +} diff --git a/manager_test.go b/manager_test.go new file mode 100644 index 0000000..821ea68 --- /dev/null +++ b/manager_test.go @@ -0,0 +1,827 @@ +package aferosteps + +import ( + "errors" + "io" + "os" + "testing" + + "github.com/cucumber/godog" + "github.com/nhatthm/aferomock" + "github.com/spf13/afero" + "github.com/spf13/afero/mem" + "github.com/stretchr/testify/assert" +) + +func newManager(t *testing.T, mockFs aferomock.FsMocker) *Manager { + t.Helper() + + fs := afero.NewOsFs() + + if mockFs != nil { + fs = mockFs(t) + } + + return NewManager(WithDefaultFs(fs)) +} + +func TestManager_Track(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + path string + expectedResult []string + expectedError string + }{ + { + scenario: "could not stat file", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", ".github"). + Return(nil, errors.New("stat error")) + }), + path: ".github/workflows/unknown.yaml", + expectedResult: []string{}, + expectedError: `could not stat(".github"): stat error`, + }, + { + scenario: "file exists", + path: ".github/workflows/test.yaml", + expectedResult: []string{}, + }, + { + scenario: "file does not exist", + path: ".github/workflows/unknown.yaml", + expectedResult: []string{".github/workflows/unknown.yaml"}, + }, + { + scenario: "parent does not exist", + path: ".github/unknown/test.yaml", + expectedResult: []string{".github/unknown"}, + }, + { + scenario: "parent does not exist (level 3)", + path: ".github/workflows/level3/test.yaml", + expectedResult: []string{".github/workflows/level3"}, + }, + { + scenario: "parent does not exist (level 2)", + path: ".github/level2/test.yaml", + expectedResult: []string{".github/level2"}, + }, + { + scenario: "level 1 does not exist", + path: "level1", + expectedResult: []string{"level1"}, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.track(defaultFs, tc.path) + + assert.Equal(t, tc.expectedResult, m.trackedFiles[defaultFs]) + + if tc.expectedError == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tc.expectedError) + } + }) + } +} + +func TestManager_Chmod(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + path string + perm string + expectedError string + }{ + { + scenario: "file not exist", + path: "unknown", + perm: "0755", + expectedError: "chmod unknown: no such file or directory", + }, + { + scenario: "wrong perm", + perm: "perm", + expectedError: "strconv.ParseUint: parsing \"perm\": invalid syntax", + }, + { + scenario: "success", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Chmod", "unknown", os.FileMode(0o755)). + Return(nil) + }), + path: "unknown", + perm: "0755", + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.chmod(tc.path, tc.perm) + + if tc.expectedError == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tc.expectedError) + } + }) + } +} + +func TestManager_RemoveFile(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + path string + expectedError string + }{ + { + scenario: "file not exist", + path: "unknown", + }, + { + scenario: "could not remove", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("RemoveAll", "unknown"). + Return(errors.New("remove error")) + }), + path: "unknown", + expectedError: "remove error", + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.removeFile(tc.path) + + if tc.expectedError == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tc.expectedError) + } + }) + } +} + +func TestManager_CreateFile(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + expectedError string + }{ + { + scenario: "could not track directory", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, errors.New("stat error")) + }), + expectedError: "could not track file: could not stat(\"level1\"): stat error", + }, + { + scenario: "could not create parent directory", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, os.ErrNotExist) + + fs.On("MkdirAll", "level1/level2", os.FileMode(0o755)). + Return(errors.New("mkdir error")) + }), + expectedError: "could not mkdir \"level1/level2\": mkdir error", + }, + { + scenario: "could not create file", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, os.ErrNotExist) + + fs.On("MkdirAll", "level1/level2", os.FileMode(0o755)). + Return(nil) + + fs.On("Create", "level1/level2/file.txt"). + Return(nil, errors.New("create error")) + }), + expectedError: "could not create \"level1/level2/file.txt\": create error", + }, + { + scenario: "success", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, os.ErrNotExist) + + fs.On("MkdirAll", "level1/level2", os.FileMode(0o755)). + Return(nil) + + fs.On("Create", "level1/level2/file.txt"). + Return(mem.NewFileHandle(mem.CreateFile("file.txt")), nil) + }), + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.createFile("level1/level2/file.txt") + + if tc.expectedError == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tc.expectedError) + } + }) + } +} + +func TestManager_CreateFileWithContent(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + expectedError string + }{ + { + scenario: "could not track directory", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, errors.New("stat error")) + }), + expectedError: "could not track file: could not stat(\"level1\"): stat error", + }, + { + scenario: "could not create parent directory", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, os.ErrNotExist) + + fs.On("MkdirAll", "level1/level2", os.FileMode(0o755)). + Return(errors.New("mkdir error")) + }), + expectedError: "could not mkdir \"level1/level2\": mkdir error", + }, + { + scenario: "could not create file", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, os.ErrNotExist) + + fs.On("MkdirAll", "level1/level2", os.FileMode(0o755)). + Return(nil) + + fs.On("Create", "level1/level2/file.txt"). + Return(nil, errors.New("create error")) + }), + expectedError: "could not create \"level1/level2/file.txt\": create error", + }, + { + scenario: "could not write file", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, os.ErrNotExist) + + fs.On("MkdirAll", "level1/level2", os.FileMode(0o755)). + Return(nil) + + f := mem.NewFileHandle(mem.CreateFile("file.txt")) + _ = f.Close() // nolint: errcheck + + fs.On("Create", "level1/level2/file.txt"). + Return(f, nil) + }), + expectedError: "could not write file \"level1/level2/file.txt\": File is closed", + }, + { + scenario: "success", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, os.ErrNotExist) + + fs.On("MkdirAll", "level1/level2", os.FileMode(0o755)). + Return(nil) + + f := mem.NewFileHandle(mem.CreateFile("file.txt")) + + fs.On("Create", "level1/level2/file.txt"). + Return(f, nil) + }), + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.createFileWithContent("level1/level2/file.txt", &godog.DocString{Content: "hello world!"}) + + if tc.expectedError == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tc.expectedError) + } + }) + } +} + +func TestManager_CreateDirectory(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + expectedError string + }{ + { + scenario: "could not track directory", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, errors.New("stat error")) + }), + expectedError: "could not track directory: could not stat(\"level1\"): stat error", + }, + { + scenario: "could not create directory", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(aferomock.NewFileInfo(), nil) + + fs.On("Stat", "level1/level2"). + Return(aferomock.NewFileInfo(), nil) + + fs.On("Stat", "level1/level2/level3"). + Return(nil, os.ErrNotExist) + + fs.On("MkdirAll", "level1/level2/level3", os.FileMode(0o755)). + Return(errors.New("mkdir error")) + }), + expectedError: "could not mkdir \"level1/level2/level3\": mkdir error", + }, + { + scenario: "success", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, os.ErrNotExist) + + fs.On("MkdirAll", "level1/level2/level3", os.FileMode(0o755)). + Return(nil) + }), + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.createDirectory("level1/level2/level3") + + if tc.expectedError == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tc.expectedError) + } + }) + } +} + +func TestManager_AssertFileExists(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + expectedError bool + }{ + { + scenario: "stat error", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(nil, errors.New("stat error")) + }), + expectedError: true, + }, + { + scenario: "file not found", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(nil, os.ErrNotExist) + }), + expectedError: true, + }, + { + scenario: "no error", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(aferomock.NewFileInfo(func(i *aferomock.FileInfo) { + i.On("IsDir").Return(false) + }), nil) + }), + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.assertFileExists("level1/file.txt") + + if tc.expectedError { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} + +func TestManager_AssertDirExists(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + expectedError bool + }{ + { + scenario: "stat error", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, errors.New("stat error")) + }), + expectedError: true, + }, + { + scenario: "file not found", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(nil, os.ErrNotExist) + }), + expectedError: true, + }, + { + scenario: "no error", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1"). + Return(aferomock.NewFileInfo(func(i *aferomock.FileInfo) { + i.On("IsDir").Return(true) + }), nil) + }), + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.assertDirectoryExists("level1") + + if tc.expectedError { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} + +func TestManager_AssertFileContent(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + expectedError bool + }{ + { + scenario: "stat error", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(nil, errors.New("stat error")) + }), + expectedError: true, + }, + { + scenario: "file not found", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(nil, os.ErrNotExist) + }), + expectedError: true, + }, + { + scenario: "different content", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(aferomock.NewFileInfo(func(i *aferomock.FileInfo) { + i.On("IsDir").Return(false) + }), nil) + + fs.On("Open", "level1/file.txt"). + Return(mem.NewFileHandle(mem.CreateFile("file.txt")), nil) + }), + expectedError: true, + }, + { + scenario: "success", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(aferomock.NewFileInfo(func(i *aferomock.FileInfo) { + i.On("IsDir").Return(false) + }), nil) + + f := mem.NewFileHandle(mem.CreateFile("file.txt")) + _, _ = f.WriteString("hello world") // nolint: errcheck + _, _ = f.Seek(0, io.SeekStart) // nolint: errcheck + + fs.On("Open", "level1/file.txt"). + Return(f, nil) + }), + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.assertFileContent("level1/file.txt", &godog.DocString{Content: "hello world"}) + + if tc.expectedError { + t.Log(err) + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} + +func TestManager_AssertFileContentRegexp(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + expectedError bool + }{ + { + scenario: "stat error", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(nil, errors.New("stat error")) + }), + expectedError: true, + }, + { + scenario: "file not found", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(nil, os.ErrNotExist) + }), + expectedError: true, + }, + { + scenario: "different content", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(aferomock.NewFileInfo(func(i *aferomock.FileInfo) { + i.On("IsDir").Return(false) + }), nil) + + fs.On("Open", "level1/file.txt"). + Return(mem.NewFileHandle(mem.CreateFile("file.txt")), nil) + }), + expectedError: true, + }, + { + scenario: "success", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(aferomock.NewFileInfo(func(i *aferomock.FileInfo) { + i.On("IsDir").Return(false) + }), nil) + + f := mem.NewFileHandle(mem.CreateFile("file.txt")) + _, _ = f.WriteString("hello world") // nolint: errcheck + _, _ = f.Seek(0, io.SeekStart) // nolint: errcheck + + fs.On("Open", "level1/file.txt"). + Return(f, nil) + }), + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.assertFileContentRegexp("level1/file.txt", &godog.DocString{Content: "hello "}) + + if tc.expectedError { + t.Log(err) + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} + +func TestManager_AssertFilePerm(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + perm string + expectedError bool + }{ + { + scenario: "invalid perm", + perm: "invalid", + expectedError: true, + }, + { + scenario: "stat error", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(nil, errors.New("stat error")) + }), + perm: "0755", + expectedError: true, + }, + { + scenario: "file not found", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(nil, os.ErrNotExist) + }), + perm: "0755", + expectedError: true, + }, + { + scenario: "different perm", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(aferomock.NewFileInfo(func(i *aferomock.FileInfo) { + i.On("Mode").Return(os.FileMode(0o644)) + }), nil) + }), + perm: "0755", + expectedError: true, + }, + { + scenario: "success", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", "level1/file.txt"). + Return(aferomock.NewFileInfo(func(i *aferomock.FileInfo) { + i.On("Mode").Return(os.FileMode(0o755)) + }), nil) + }), + perm: "0755", + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + m := newManager(t, tc.mockFs) + err := m.assertFilePerm("level1/file.txt", tc.perm) + + if tc.expectedError { + t.Log(err) + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} + +func TestManager_AssertFileTreeEqual(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + expectedError bool + }{ + { + scenario: "stat error", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", ".github"). + Return(nil, errors.New("stat error")) + }), + expectedError: true, + }, + { + scenario: "success", + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + expected := ` +- workflows: + - golangci-lint.yaml + - test.yaml +` + + m := newManager(t, tc.mockFs) + err := m.assertTreeEqualInPath(".github", &godog.DocString{Content: expected}) + + if tc.expectedError { + t.Log(err) + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} + +func TestManager_AssertFileTreeContains(t *testing.T) { + t.Parallel() + + testCases := []struct { + scenario string + mockFs aferomock.FsMocker + expectedError bool + }{ + { + scenario: "stat error", + mockFs: aferomock.MockFs(func(fs *aferomock.Fs) { + fs.On("Stat", ".github"). + Return(nil, errors.New("stat error")) + }), + expectedError: true, + }, + { + scenario: "success", + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + + expected := ` +- workflows: + - golangci-lint.yaml + - test.yaml +` + + m := newManager(t, tc.mockFs) + err := m.assertTreeContainsInPath(".github", &godog.DocString{Content: expected}) + + if tc.expectedError { + t.Log(err) + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} diff --git a/testing.go b/testing.go new file mode 100644 index 0000000..1942450 --- /dev/null +++ b/testing.go @@ -0,0 +1,19 @@ +package aferosteps + +import "fmt" + +type tError struct { + err error +} + +func (t *tError) Errorf(format string, args ...interface{}) { + t.err = fmt.Errorf(format, args...) // nolint: goerr113 +} + +func (t *tError) LastError() error { + return t.err +} + +func teeError() *tError { + return &tError{} +} diff --git a/util.go b/util.go new file mode 100644 index 0000000..15a3876 --- /dev/null +++ b/util.go @@ -0,0 +1,57 @@ +package aferosteps + +import ( + "fmt" + "os" + "regexp" + "strconv" + "strings" +) + +func strToPerm(s string) (os.FileMode, error) { + base := 10 + if strings.HasPrefix(s, "0") { + base = 8 + } + + mode, err := strconv.ParseUint(s, base, 32) + if err != nil { + return 0, err + } + + return os.FileMode(mode), nil +} + +func mustNoError(err error) { + if err != nil { + panic(err) + } +} + +func fileContentRegexp(s string) string { + pattern := regexp.MustCompile(``) + matches := pattern.FindAllString(s, -1) + cnt := len(matches) + + if cnt == 0 { + return regexp.QuoteMeta(s) + } + + replacementsBefore := make([]string, 0, cnt*2) + replacementAfter := make([]string, 0, cnt*2) + + for i, match := range matches { + token := fmt.Sprintf("", i) + + replacementsBefore = append(replacementsBefore, match, token) + replacementAfter = append(replacementAfter, token, strings.TrimPrefix(strings.TrimSuffix(match, "/>"), "