GithubHelp home page GithubHelp logo

terratest-maven-plugin

This is a Maven plugin for running Terratests or any go test in your repository. Terratest is used to create infrastructure tests with popular language go. With this plugin you can run these tests, create HTML reports out of the box with your beloved maven build pipeline. You can use this plugin to run all your go tests, it has no explicit dependency on terratest.

CircleCI License: MIT Maven Central

Usage

Include in your pom.xml

<build>
    ...
        <plugins>
            ...
            <plugin>
                <groupId>com.github.terratest-maven-plugin</groupId>
                <artifactId>terratest-maven-plugin</artifactId>
                <version>1.0.1</version>
                <configuration>
                    <terraTestPath>{[ABSOLUTE-PATH-TO-TERRATESTS]}</terraTestPath>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>run-tests</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
        ...
</build>

Goals

Goal Description Default Lifecycle Phase
terratest:compile Compile Terratests inside the terratestPath directory compile
terratest:run-tests Run go tests inside terratestPath test

Required parameters

<configuration>
   <terraTestPath>{[ABSOLUTE-PATH-TO-TERRATESTS]}</terraTestPath>
</configuration>

Sets the working directory for the goal compile or run-tests

Example

For examples, check out: Terratest maven plugin examples repository.

Optional parameters

Generating logs

You can generate log files into your terraTestPath directory from the stdOut and stdErr of the go test results. Use the following parameter:

<configuration>
    ...
    <createLogFile>true</createLogFile>
    ...
</configuration>

This will generate an terratest-output.log and an terratest-error-output.log inside your terraTestPath

Generating HTML report

Only used in run-tests goal
You can have an HTML report about your test results into your terraTestPath directory as index.html.

HTML report example
Use the following parameter:

<configuration>
...
 <generateHtmlReport>true</generateHtmlReport>
...
</configuration>

Use json output

You can set the useJsonOutput parameter so go test results will be logged as json. This combined with createLogFile parameter eases further processing.

<configuration>
...
 <useJsonOutput>true</useJsonOutput>
...
</configuration>

Example output:

{"Time":"2021-03-24T09:06:19.39012+01:00","Action":"run","Package":"io/jinfra/terratest/maven/plugin/tests/m/v2","Test":"TestValidDockerTestMavenProject"}
{"Time":"2021-03-24T09:06:19.390426+01:00","Action":"output","Package":"io/jinfra/terratest/maven/plugin/tests/m/v2","Test":"TestValidDockerTestMavenProject","Output":"=== RUN   TestValidDockerTestMavenProject\n"}

Skip tests

Only used in run-tests goal
terratest-maven-plugin integrates with the widely used -DskipTests, so if you run this for example:

mvn clean install -DskipTests

your terratests won't run. Of course, you can set it directly in the plugin/pluginManagement section:

<configuration>
...
<skipTests>true</skipTests>
...
</configuration>

The effect will be the same. If you want to compile your go tests even if tests are disabled use the terratest:compile goal, for example like this:

<plugin>
    <groupId>com.github.terratest-maven-plugin</groupId>
    <artifactId>terratest-maven-plugin</artifactId>
    <configuration>
        <terraTestPath>${project.basedir}/docker-test</terraTestPath>
        </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

This will bound to compile lifecycle by default. If you want to change this behaviour, use the phase parameter in execution.

Disable test caching

Only used in run-tests goal
Go can use a mechanics called test caching. This is enabled by default, but you can switch it off by using the following parameter:

<configuration>
...
<skipTests>true</skipTests>
...
</configuration>

Add further arguments

You can include further arguments with the go test or compiling. use the following parameter:

<configuration>
...
    <arguments>
        <param>arg1</param>
        <param>arg1</param>
    </arguments>
...
</configuration>

For full reference of the arguments you can use with go test, see the Go test reference

Contribution

If you'd like to contribute, please feel free. This is an MIT licenced application, so you can use it, extends it however you want. :)

Build the project

Clone this project. Use maven 3.0.0 or newer for building. Once you done with your changes and sufficient amount of tests have been done, create a pull request.

Terratest Maven Plugin's Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.