Running Tests Locally - rancher/shepherd GitHub Wiki
This section explains how to run the tests locally and accepts you've read and followed the below sections:
The configuration file is a necessary file to run the tests that use Shepherd, the file format can be in either YAML or JSON. This file contains information about your testing environment and preferences.
It can be existing fields that are used in the tests; to name a few, rancher server hostname or admin token, test cluster provisioning options, choosing what cluster to upgrade, choosing a cluster to run RBAC or charts tests.
When adding a new test, you can add new fields to this configuration that are going to be used in your tests; you can also modify, or directly use the existing ones.
Before starting: This section needs a running Rancher Server, it can be an HA instance or a Rancher Docker.
The starting point to create your first configuration is the shepherd client's parent field which includes your rancher server related information:
rancher:
adminPassword: <string>
adminToken: <string>
caCerts: <string>
caFile: <string>
cleanup: <bool>
clusterName: <string>
host: <string>
insecure: <bool>
shellImage: <string>
Whenever you use the shepherd client, the above rancher
parent will need to be in your configuration file to instantiate the client.
- Create a configuration file in the root dir
touch $HOME/my-first-cattle-config.yaml
- Add your rancher instance host by editing this file
vim $HOME/my-first-cattle-config.yaml
:rancher: // After creating a rancher instance with host my-rancher-server-host.com or localhost host: myrancherserver.com
- The client needs an API token from your Rancher instance.
This is a bearer token that you can create or use an existing one.
To create your first token on your Rancher please follow Rancher Docs - Creating API Keys.
Add your rancher instance API bearer token by editing this file
vim $HOME/my-first-cattle-config.yaml
:rancher: host: my-rancher-server-host.com adminToken: my-new-generated-bearer-token
Shepherd needs an environment variable called CATTLE_TEST_CONFIG
to be set to run the tests.
This environment variable is the path to your configuration file.
You can export CATTLE_TEST_CONFIG
with the command export CATTLE_TEST_CONFIG=$HOME/my-first-cattle-config.yaml
to run the tests with the go test command in your terminal.
If you prefer to store this variable in your shell configuration you can add this command to your shell configuration file such as zshrc or bashrc.
For this section, you'll create a file that points to the environment variable.
This is one of the many ways, to name a few other approaches that this section won't cover; using .env
file or setting this environment variable on your VSCode Personal Preferences Customization.
- Create a
.zprofile
file in your testing project - Add your
CATTLE_TEST_CONFIG
path to this file as:export CATTLE_TEST_CONFIG=$HOME/my-first-cattle-config.yaml
Running your tests depends on what testing stack you are using in your testing project.
This section covers how to run the test suites in rancher/rancher with testify suites.
To run the test with the go test command, the configuration file environment variable has to be set. You can set it by following this.
You can use the go test command to run a single test:
/usr/local/go/bin/go test -timeout <int> <s/m> ^TestProjectUserTestSuite/TestCreateNamespaceProjectMember$
github.com/rancher/rancher/tests/v2/integration/projects -v
You can use the go test command to run the whole suite:
/usr/local/go/bin/go test -timeout <int> <s/m> ^TestProjectUserTestSuite$ github.com/rancher/rancher/tests/v2/integration/projects -v
Before running the tests with VSCode, installing Go in Visual Code extension is highly recommended. This extension bundles many good and required Go-related LSP servers, Linters, Formatters, and Debugger.
To run the test with VSCode, the configuration file environment variable has to be set. You can set it by following this.
On top of each test and suite, there is an option to RUN or DEBUG them. You can use Run Test option.