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

Running terratest #34

Open
issacg opened this issue Jul 28, 2020 · 2 comments
Open

Running terratest #34

issacg opened this issue Jul 28, 2020 · 2 comments
Labels
question Further information is requested

Comments

@issacg
Copy link

issacg commented Jul 28, 2020

Hey,

Wondering if there's a reason why this repo doesn't supply a hook for running tests written with terratest (perhaps by default expecting to run go test from an expected test/ subdirectory)?

Sorta like:

- id: terratest
          name: terratest
          description: "Run terratest unit tests"
          entry: sh -c "cd test; go test -count=1 -timeout 30m -tags=unit"
          language: system
          files: '\.tf$'
          pass_filenames: false

Thanks!

@brikis98 brikis98 added the question Further information is requested label Jul 28, 2020
@brikis98
Copy link
Member

Terratest is typically used to run infrastructure tests, which can take a while—5, 10, or 30 minutes is normal, and tests that take over an hour are possible too. Also, those tests typically require authentication (e.g., authenticating too AWS) and have lots of side effects (e.g., creating resources in AWS), so if you interrupt them part way through (e.g., via CTRL+C), it leaves your environment in a messy state.

Do you really want a pre-commit hook that takes that long, has lots of environmental requirements, and can't be interrupted? Seems like that would severely discourage committing early and often...

@issacg
Copy link
Author

issacg commented Jul 29, 2020

That's true... if they need to run ~5+ minutes.

But if we've tried to keep our "unit" tests slim, then they may not need to run 5 minutes or more on commit.

The use-case that got me to ask was for a string manipulation module, which can run real unit tests, in the sense of classic software. That takes a few seconds, most of which goes to compiling Go.

Microsoft blogged about a cute idea where they talk about limiting "unit" tests to tests which use terraform plan and parsing the output of that, vs "integration" to tests that run an apply/validate/destroy cycle. This can keep testing down to a few tens of seconds to a few minutes if modules under testing don't use a heck of a lot of remote inputs and help lint before things are in Git.

But the question is excellent, and in lieu of making it easy on devs to shoot themselves in the foot, maybe there can be a FAQ entry on this with a solution of creating a local hook as I did, and with a big fat caveat emptor against why folks might want to think twice about it.

For me this was initially annoying, as I use Go sparingly enough that navigating through installing Go, remembering how to use it (modules, packages, etc) and which tools to use took me a few hours that could have been spent just as easily on writing better tests (or better Terraform!) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants