Contributing to mesheryctl e2e tests using BATS

Running tests locally

Prerequisites

  • A verified account in your chosen provider which integrate with Meshery.
  • bash as shell terminal
  • Installations of Bats, Golang, NodeJS and Makefiles for Native OS build (Optional for docker based build).
  • Kubernetes clusters (Required for connection to Kubernetes test cases)
  • Meshery server up and running

Running the tests

  • make sure you are in meshery/mesheryctl/tests/e2e directory
  • run bats run_tests.bash

It takes some time since meshery server is deployed to your Kubernetes cluster

Writing your own tests

Folder structure

The tests will be available in mesheryctl/tests/e2e folder with the following structure which is donedone to follow the code base structure of mesheryctl

β”œβ”€β”€ aaa-<command>
β”œβ”€β”€ bbb-<command>
β”œβ”€β”€ ...
β”œβ”€β”€ yyy-<command>
β”œβ”€β”€ zzz-<command>
β”œβ”€β”€ helpers
β”œβ”€β”€ README.md
β”œβ”€β”€ run_tests.bash
β”œβ”€β”€ setup_suite.bash
└── teardown_suite.bash

Naming convention

Tips

Bats will run the tests sequentially so we use a prefix code alphanumeric to be able to order tests as required when necessary

ex: you need to import a model before being able to view the details of that model

Folder

  • prefix: 3 digits alphanumeric code
  • name: command under test

example: 011-design

Test file

  • prefix: 2 digits numeric code
  • name: subcommand under test
  • extension: bats

example: 05-list.bats

For consistency, we will keep the prefix 00- for the command under test in the folder and subcommands will start at 01-
Here an example with mesheryctl model command

002-model/
β”œβ”€β”€ 00-model.bats
└── 01-model-list.bats

Find Tests here

Refer to Meshery Test Plan for test scenarios.

4 Likes

Here is a bit of prior use of BATS in the Meshery project- Here is that prior art that I referred to - meshery-consul/tests/README.md at master Β· meshery/meshery-consul Β· GitHub. There may well be insights and learning to take from here.

Here is a new Meshery Docs page on contributing to mesheryctl end-to-end testing - Contributing to Meshery CLI End-to-End Tests | Meshery

@Riya @Matthieu.EVRIN good job!