Skip to content

Test

testLicense

Test the license of a project using reuse.

Types:

  • testLicense:
    • enable (bool): Optional. Defaults to false.

Example:

1
2
3
4
5
{
  testLicense = {
    enable = true;
  };
}
m . /testLicense

testPullRequest

Test a pull request on any of the supported platforms using Danger.js.

For more information on how to use Danger.js, please refer to its Getting started guide.

Types:

  • testPullRequest:
    • modules (attrsOf moduleType): Optional. Danger configurations to use. Defaults to { }.
  • moduleType (submodule):
    • dangerfile (path): Path to a Javascript or Typescript dangerfile.
    • extraArgs (listOf str): Extra arguments to pass to the danger executable.
    • setup (listOf package): Optional. Makes Environment or Makes Secrets to source (as in Bash's source) before anything else. Defaults to [ ].

Example:

{
  projectPath,
  ...
}:
{
  testPullRequest = {
    modules = {
      github = {
        dangerfile = projectPath "/dangerfiles/github.ts";
        extraArgs = [
          # Extra arguments for my dangerfile
          "--config"
          "strict"
        ];
      };
      gitlab = {
        dangerfile = projectPath "/dangerfiles/gitlab.ts";
      };
    };
  };
}
import { argv } from "node:process";

import { danger, fail, warn } from "danger";

const nCommits = danger.git.commits.length;
const strict = argv[6] === "strict";

if (nCommits > 1) {
  msg = `Only one commit per PR - Commits: ${nCommits}`
  if (strict) {
    fail(msg);
  }
  else {
    warn(msg);
  }
}
$ m . /testPullRequest/github

testPython

Test Python code with pytest.

Types:

  • testPython (attrsOf targetType): Optional. Mapping of names to pytest targets. Defaults to { }.
  • targetType (submodule):

    • python (enum ["3.9" "3.10" "3.11" "3.12"]): Python interpreter version that your package/module is designed for.
    • src (str): Path to the file or directory that contains the tests code.
    • searchPaths (asIn makeSearchPaths): Optional. Arguments here will be passed as-is to makeSearchPaths. Defaults to makeSearchPaths's defaults.
    • extraFlags (listOf str): Optional. Extra command line arguments to propagate to pytest. Defaults to [ ].
    • extraSrcs (attrsOf package): Optional. Place extra sources at the same level of your project code so you can reference them via relative paths.

    The final test structure looks like this:

    1
    2
    3
    4
    5
    6
    7
    8
    /tmp/some-random-unique-dir
    ├── __project__  # The entire source code of your project
       ├── ...
       └── path/to/src
    ... # repeat for all extraSrcs
    ├── "${extraSrcName}"
       └── "${extraSrcValue}"
    ...
    

    And we will run pytest like this:

    pytest /tmp/some-random-unique-dir/__project__/path/to/src
    

    Defaults to { }.

Example:

1
2
3
4
5
{
  testPython = {
    example.src = "/test/test-python";
  };
}
m . /testPython/example
1
2
3
4
5
6
7
8
9
$ tree test/test-python/

  test/test-python/
  └── test_something.py

$ cat test/test-python/test_something.py

  1 def test_one_plus_one_equals_two() -> None:
  2     assert (1 + 1) == 2

testTerraform

Test Terraform code by performing a terraform plan over the specified Terraform modules.

Types:

  • testTerraform:
    • modules (attrsOf moduleType): Optional. Path to Terraform modules to lint. Defaults to { }.
  • moduleType (submodule):
    • setup (listOf package): Optional. Makes Environment or Makes Secrets to source (as in Bash's source) before anything else. Defaults to [ ].
    • src (str): Path to the Terraform module.
    • version (enum [ "0.14" "0.15" "1.0" ]): Terraform version your module is built with.
    • debug (bool): Optional. Enable maximum level of debugging and remove parallelism so logs are clean. Defaults to false.

Example:

{
  testTerraform = {
    modules = {
      module1 = {
        src = "/my/module1";
        version = "0.14";
      };
      module2 = {
        src = "/my/module2";
        version = "1.0";
      };
    };
  };
}
$ m . /testTerraform/module1