Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add go install compatibility #23

Merged
merged 7 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/build_release_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

- name: Install plugin framework and example plugins
run: |
pip install ./plugins ./example/plugin-example
pip install ./python-plugins ./example/plugin-example

- uses: hashicorp/setup-terraform@v2
with:
Expand All @@ -59,8 +59,8 @@ jobs:
- name: Install Go toolchain
uses: actions/setup-go@v4
with:
go-version-file: "src/go.mod"
cache-dependency-path: "src/go.sum"
go-version-file: "go.mod"
cache-dependency-path: "go.sum"

- name: Generate Binary Name
id: binary_name
Expand All @@ -78,8 +78,7 @@ jobs:

- name: Compile Test Binary
run: |
cd src/
go test -c -o ../bin/${{ steps.binary_name.outputs.binary_name }}
go build -o bin/${{ steps.binary_name.outputs.binary_name }}

- name: Run Example Terraform Tests
run: |
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/run_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: Install plugin framework and example plugins
run: |
pip install ./plugins ./example/plugin-example
pip install ./python-plugins ./example/plugin-example

- name: Run all pre-commit hooks
run: |
Expand All @@ -51,13 +51,12 @@ jobs:
- name: Install Go toolchain
uses: actions/setup-go@v4
with:
go-version-file: "src/go.mod"
cache-dependency-path: "src/go.sum"
go-version-file: "go.mod"
cache-dependency-path: "go.sum"

- name: Code Consistency Checks
if: matrix.os == 'ubuntu-latest'
run: |
cd src/
output=$(gofmt -l .)
echo "$output"
test -z $output
Expand All @@ -74,8 +73,7 @@ jobs:

- name: Compile Test Binary
run: |
cd src/
go test -c -o ../bin/${{ steps.binary_name.outputs.binary_name }}
go build -o bin/${{ steps.binary_name.outputs.binary_name }}

- name: Run Example Terraform Tests
run: |
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/assertions/assertions.go → assertions/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
"schrodinger.com/infra-tester/plugins"
"schrodinger.com/infra-tester/utils"
"github.com/schrodinger/infra-tester/plugins"
"github.com/schrodinger/infra-tester/utils"
)

type Assertion struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/schrodinger/infra-tester/plugins"
"github.com/stretchr/testify/assert"
"schrodinger.com/infra-tester/plugins"
)

func GetCustomAssertionImplementation(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/docs/extending_infra_tester.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You can install the plugin host by installing the `infra-tester-plugins` PIP pac

As of now, you can install the plugin host through PIP using the following command:
```shell
pip install "git+https://github.com/schrodinger/infra-tester.git#subdirectory=plugins/"
pip install "git+https://github.com/schrodinger/infra-tester.git#subdirectory=python-plugins/"
```

We are currently looking into adding this package to the official PIP registry.
Expand Down
7 changes: 3 additions & 4 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ See [**official Terraform documentation**](https://developer.hashicorp.com/terra
# Clone the repo
$ git clone [email protected]:schrodinger/infra-tester.git

# Go to src directory and build the executable
$ cd src/
$ go test -c -o infra-tester
# Build the executable
$ go build -o bin/infra-tester

# Move the binary to a directory in the $PATH
$ sudo mv infra-tester /usr/local/bin
Expand Down Expand Up @@ -87,7 +86,7 @@ Once *infra-tester* is set up, run the [example tests](https://github.com/schrod

# Install plugin example assertions to run test
$ pip install \
"git+https://github.com/schrodinger/infra-tester.git#subdirectory=plugins/" \
"git+https://github.com/schrodinger/infra-tester.git#subdirectory=python-plugins/" \
"git+https://github.com/schrodinger/infra-tester.git#subdirectory=example/plugin-example/"

# Run the tests
Expand Down
19 changes: 9 additions & 10 deletions docs/docs/test_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
A test summary is generated at the end of the test if *infra-tester* is run with the `-test.v` flag.

```title="Test Summary"
-- PASS: TestMain (4.39s)
--- PASS: TestMain/<TestPlanName> (4.39s)
--- PASS: TestMain/<TestPlanName>/<TestName> (0.25s)
--- PASS: TestMain/<TestPlanName>/<TestName>/Plan (0.25s)
--- PASS: TestMain/<TestPlanName>/<TestName>/Plan/<PlanAssertion1> (0.00s)
--- PASS: TestMain/<TestPlanName>/<TestName>/Plan/<PlanAssertion2> (0.00s)
-- PASS: Tests (4.39s)
--- PASS: Tests/<TestPlanName> (4.39s)
--- PASS: Tests/<TestPlanName>/<TestName> (0.25s)
--- PASS: Tests/<TestPlanName>/<TestName>/Plan (0.25s)
--- PASS: Tests/<TestPlanName>/<TestName>/Plan/<PlanAssertion1> (0.00s)
--- PASS: Tests/<TestPlanName>/<TestName>/Plan/<PlanAssertion2> (0.00s)
...
--- PASS: TestMain/<TestPlanName>/<TestName>/Apply (0.25s)
--- PASS: TestMain/<TestPlanName>/<TestName>/Apply/<ApplyAssertion1> (0.00s)
--- PASS: TestMain/<TestPlanName>/<TestName>/Apply/<ApplyAssertion2> (0.00s)
--- PASS: Tests/<TestPlanName>/<TestName>/Apply (0.25s)
--- PASS: Tests/<TestPlanName>/<TestName>/Apply/<ApplyAssertion1> (0.00s)
--- PASS: Tests/<TestPlanName>/<TestName>/Apply/<ApplyAssertion2> (0.00s)
...
PASS
ok schrodinger.com/infra-tester 4.890s
```

In the above test summary:
Expand Down
24 changes: 12 additions & 12 deletions docs/docs/writing_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ You should see the logs appear as the test runs, and finally, the test output is
printed.

```
--- PASS: TestMain (3.35s)
--- PASS: TestMain/Time (2.97s)
--- PASS: TestMain/Time/CurrentTimeOutputTests (1.03s)
--- PASS: TestMain/Time/CurrentTimeOutputTests/Apply (1.03s)
--- PASS: TestMain/Time/CurrentTimeOutputTests/Apply/TimeStringMatchesRFC3339 (0.09s)
--- PASS: Tests (3.35s)
--- PASS: Tests/Time (2.97s)
--- PASS: Tests/Time/CurrentTimeOutputTests (1.03s)
--- PASS: Tests/Time/CurrentTimeOutputTests/Apply (1.03s)
--- PASS: Tests/Time/CurrentTimeOutputTests/Apply/TimeStringMatchesRFC3339 (0.09s)
PASS
```

Expand All @@ -138,9 +138,9 @@ Let's run `infra-tester -test.v` to see what happens.

```
$ infra-tester -test.v
=== RUN TestMain
=== RUN Tests
assertions.go:117: ERROR: Failure during test validation: test 'CurrentTimeOutputTests' failed validation: assertion 'OutputMatchesRegex' for apply step failed validation because - invalid regular expression
--- FAIL: TestMain (0.36s)
--- FAIL: Tests (0.36s)
FAIL
```
As you can see, *infra-tester* runs test validation before running any of the
Expand All @@ -161,11 +161,11 @@ And now if you run *infra-tester* again, the validation passes, but the test
fails as expected:

```
--- FAIL: TestMain (1.60s)
--- FAIL: TestMain/Time (1.27s)
--- FAIL: TestMain/Time/CurrentTimeOutputTests (0.47s)
--- FAIL: TestMain/Time/CurrentTimeOutputTests/Apply (0.47s)
--- FAIL: TestMain/Time/CurrentTimeOutputTests/Apply/TimeStringMatchesRFC3339 (0.08s)
--- FAIL: Tests (1.60s)
--- FAIL: Tests/Time (1.27s)
--- FAIL: Tests/Time/CurrentTimeOutputTests (0.47s)
--- FAIL: Tests/Time/CurrentTimeOutputTests/Apply (0.47s)
--- FAIL: Tests/Time/CurrentTimeOutputTests/Apply/TimeStringMatchesRFC3339 (0.08s)
FAIL
```

Expand Down
64 changes: 64 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module github.com/schrodinger/infra-tester

go 1.19

require (
github.com/gruntwork-io/terratest v0.43.13
github.com/mitchellh/mapstructure v1.5.0
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v3 v3.0.1
)

require (
cloud.google.com/go v0.110.8 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.2 // indirect
cloud.google.com/go/storage v1.33.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/aws/aws-sdk-go v1.45.9 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.0 // indirect
github.com/hashicorp/terraform-json v0.17.1 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/mattn/go-zglob v0.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tmccombs/hcl2json v0.6.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/zclconf/go-cty v1.14.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.140.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/grpc v1.58.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
Loading