Skip to main content
Version: v4.5.0

Stack Test

On This Page

This section aims to guide the development and execution of tests for each of the Plugins and Templates that you develop.

About Stacks Test

For you to create Stacks, the StackSpot provides a simple and easy model so you can test Stacks, Templates, and Plugins.

When you finish developing a Stack, you should create and run test cases to ensure that each Template and Plugin works as expected.

Stack test structure

You need to run the tests inside the desired Stack folder, that's where all test cases for Templates and Plugins must be to be run.

Just like the structure of Templates and Plugins, to create tests, it is necessary to follow a pattern. You can create as many test cases as you like, following the steps described below:

  1. Inside the Plugin and Template create the folder "/tests";
  2. This folder should have the name of the test case you want for your Plugin or Template.

Check out the example:

./my-stack-java
. 
.
.
├── java-kafka-plugin
│ ├── template.yaml
│ ├── templates
│ └── tests
│ └── kafka-plugin-test-casep-1
│ ├── expected
│ └── inputs.yaml
└── stack.yaml

With a test case created in the /tests folder, some other elements should compose the test structure. Check below the mandatory items for a test case:

  • expected folder: The expected folder should contain all the expected files when the Template or Plugin is used to create an application.

  • target folder: The target folder is exclusively used for the Plugins test case and represents an application where the Plugin must be applied. This folder must contain the content of the app with the state before the Plugin applies that you want to test.

  • inputs.yaml file: The inputs.yaml file of a Plugin or Template test case defines all the expected inputs for each one.

info

The target folder is exclusively for Plugins test cases.

The example below is a Stack with test cases for the Template and Plugin. This example represents the structure your Stack should have after creating a test case:

./my-stack-folder
.
├── some-plugin-folder
│ ├── plugin.yaml
│ ├── templates
│ └── tests
│ └── plugin-test-case
│ ├── expected
│ ├── inputs.yaml
│ └── target
├── some-template-folder
│ ├── template.yaml
│ ├── templates
│ └── tests
│ └── template-test-case
│ ├── expected
│ └── inputs.yaml
└── stack.yaml

Create and run tests

Stacks testing provides a simple template for standardizing and running tests on Templates and Plugins structures. Tests do not cover Stack content such as Templates and Plugins of IaC components, source codes, and environment configuration files, among others.

  • To run the tests, use the command stk-legacy test.
  • To validate your Stack data, run the command stk-legacyvalidate, the test command does not cover validations from the stk-legacy validate command.

Before you start

  1. Create the tests folder in the root of your Plugin and/or Template folder.
  2. Inside the tests folder, create a folder with the name of each test case you want to create.

Example:

.plugin-or-template-folder/tests
.
├── plugin-abc-case-1
├── plugin-abc-case-2
├── template-abc-case-1
└── template-abc-case-2
  1. For each test case, create the following folders within each of them:
    • In the test cases for Templates, create the expected folder.
    • In test cases for Plugins, create expected and target folders.
  2. Create the file inputs.yaml.

Create the inputs.yaml file

You must create the inputs.yaml file in the root of the test case folder. It must contain all the Plugin or Template inputs that will be tested.

To fill in the file, you must insert the value of the field name: (name) of the Template or Plugin inputs as an attribute of inputs.yaml, and as value, a valid value according to the input type. Check the syntax of these fields in the example below:

inputs.yaml
input_text: some text value
input_bool: true
input_select: some-valid-value
input_multi_select:
- some-valid-value-1
- some-valid-value-2

Therefore, consider that your Template and Plugin have the following inputs:

Example inputs for plugin.yaml and template.yaml
inputs:
- label: "Type your name: "
name: "input_text"
type: text
default: "Jose"
- label: "42 is the answer ?"
name: "input_bool"
type: bool
- label: "what is your favorite number ?"
name: "input_int"
type: int
default: 42
- label: "Choose one or more days: "
type: multiselect
name: "input_days"
default:
- "Monday"
- "Tuesday"
items:
- "Monday"
- "Tuesday"
- "Wednesday"
- "Thursday"
- "Friday"
- "Saturday"
- "Sunday"

Your inputs.yaml file for these inputs should be:

inputs.yaml
input_text: some text value
input_bool: false
input_int: 123
input_days:
- "Monday"
- "Tuesday"
- "Wednesday"
- "Thursday"
- "Friday"
- "Saturday"
- "Sunday"

Test for Templates

To test your Templates, you must:

  1. Create and populate the file inputs.yaml.
  2. Inside the expected folder, place all the files of an application, generated using the Template you want to test.

To run the test case, run the stk-legacy test command and its options. Check out the examples below:

stk-legacy test template

Test for Plugins

In the test case for Plugins, you must:

  1. Create and populate the file inputs.yaml.
  2. Inside the expected folder, place all the files of an application, which was generated using a Template from your Stack and the Plugin you want to test already applied.
  3. Inside the target folder, you must place all the files of an application, generated using a Template or Stackfile of your Stack.

To run the test case, run the stk-legacy test command and its options. Check out the examples below:

stk-legacy test plugin

Run all tests from Stack

To run all tests of Plugins and Templates in a Stack, run the command below:

stk-legacy test stack

Was this page helpful?