test

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2019 License: LGPL-3.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Tests

This folder contains automated tests for this all modules provided in this repository using a helper library called Terratest. The tests are written in Go.

WARNING WARNING WARNING

Note #1: Many of these tests create real resources in an AWS account and then try to clean those resources up at the end of a test run. That means these tests may cost you money to run! When adding tests, please be considerate of the resources you create and take extra care to clean everything up when you're done!

Note #2: Never forcefully shut the tests down (e.g. by hitting CTRL + C) or the cleanup tasks won't run!

Note #3: We set -timeout 60m on all tests not because they necessarily take that long, but because Go has a default test timeout of 10 minutes, after which it forcefully kills the tests with a SIGQUIT, preventing the cleanup tasks from running. Therefore, we set an overlying long timeout to make sure all tests have enough time to finish and clean up.

Test Coverage

[-] ami [-] ami2 [x] bastion [x] consul [-] ecr [x] networking [x] nomad [x] nomad-datacenter [-] sgrules [x] ui-access [x] root-example

Usage Hints

Setup and Preconditions
  • To be able to run the tests you need to have a working golang setup, an AWS account and terratest needs to be installed.
  • The golang installation is described here.
  • Terratest provides a tool to beautify the test output called: terratest_log_parser. This tool will be installed when executing the tests and via the provided Makefile and calling the target make install_terratest_log_parser.
  • The AWS account to be used is automatically identified by terratest using the ~/.aws/credentials file. There the [default] entry will be used for authentication. How to configure the AWS credentials is described here.
Execute tests
  • make all
Using Stages

The tests are broken into "stages":

  • test_structure.RunTestStage(t, "teardown", func() {...})

One can skip stages by setting environment variables:

  • Skip stage teardown by setting the environment variable SKIP_teardown=true.
    • SKIP_teardown=true make TestConsulExample

Using stages will create the temporary configuration in the main folder, IGNORING the copy command into the temporary folder! This is activate once ONE SKIP_XXX statement was found.

Teardown

To tear down the debug session at least one SKIP_XXX statement has to be provided in order to use the main folder configuration settings. The suggestion is to skip the setup steps, like:

  • SKIP_setup_ami=true SKIP_setup=true make TestConsulExample
Caching

Golang is using caching and will not run the test again if no source code changes are detected.

To avoid problems with testing terraform clear the cache before every test run: go clean -testcache. This is how the Makefile is configured.

Logging

Using Terratest's logger.Log and logger.Logf functions, which log to stdout immediately instead of testing logger which only log to stdout after the completion of a test.

Run the test sequentially to avoid golang stdout buffering -p 1. This is how the Makefile is configured.

Troubleshooting
Golang: "root project import: is not within any GOPATH/src"
  • If you get an error message like root project import: [..]/test is not within any GOPATH/src you have to check out this repository in a folder-structure that fits the needs of golang.
  • This means the code has to reside in a folder-structure like this <some-folder>/src.
  • The best solution would be to just check out this repository into your GOPATH structure: cd %GOPATH/src && clone https://github.com/MatthiasScholz/cos.git which then would result in <some-folder>/src/cos containing all the code.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL