Keywords
TEST
Runs any given command and validates for the exit code. For example,
TEST "stat /var/www/html/index.html"
Or validate for a specific exit code
TEST 1, "ls /non/existing/dir"
RUN
This is very similar to TEST
but ignores if any error. This will be useful when some cleanup command to be run but that may fail.
For example,
RUN losetup -d /dev/non_existing_dev
EXPECT
Runs the given command and validates the output only if exit code of the command is zero.
EXPECT "node1.example.com", "hostname"
TEST_WITHIN
To be implemented
EXPECT_WITHIN
To be implemented
EXISTS
To be implemented
EQUAL
Test if given two values are Equal
EQUAL var1, 100, "Test if var1 == 100"
NOT_EQUAL
Test if given two values are not Equal.
NOT_EQUAL var1, 100, "Test if var1 != 100"
TRUE
Test any expression
TRUE <expr>, "test title", "message to show on failure"
TRUE 42 % 2 == 0, "Even number test for 42"
hn = TEST "hostname"
TRUE hn == "node1.example.com", "hostname test for node1.example.com", "Actual: #{hn}"
FALSE
Same as TRUE
but validate for false
USE_NODE
To switch node to execute the tests.
# Approach 1: set required node before the test statements
USE_NODE "node1.example.com"
TEST "command1.."
TEST "command2.."
USE_NODE "node2.example.com"
TEST "command1.."
TEST "command2.."
# Approach 2: Use Block syntax when node switch is required
# Default node set
USE_NODE "node1.example.com"
TEST "command 1"
TEST "command 2"
USE_NODE "node2.example.com" do
TEST "command 3"
TEST "command 4"
end
# continue running commands in default node
TEST "command 5"
USE_REMOTE_PLUGIN
Default remote plugin is ssh
, change it when required. Similar to NODE
keyword, this also supports Block syntax.
USE_NODE "node1.example.com"
USE_REMOTE_PLUGIN "ssh"
TEST "command 1"
USE_REMOTE_PLUGIN "docker" do
USE_NODE "node2.example.com" do
TEST "command 2"
end
end
# Continue with default plugin
TEST "command 3"
USE_SSH_USER
Set SSH user. Default is "root". This option is only applicable with USE_REMOTE_PLUGIN ssh
.
USE_NODE "node1.example.com"
USE_REMOTE_PLUGIN "ssh"
USE_SSH_USER "ubuntu"
TEST "stat ~/Public"
USE_SSH_PEM_FILE
Set SSH pem file path. Default is ~/.ssh/id_rsa
. This option is only applicable with USE_REMOTE_PLUGIN ssh
.
USE_NODE "node1.example.com"
USE_REMOTE_PLUGIN "ssh"
USE_SSH_USER "ubuntu"
USE_SSH_PEM_FILE "~/.ssh/automation.pem"
TEST "stat ~/Public"
USE_SSH_SUDO
Use sudo
with all the commands. Default is false
. This option is only applicable with USE_REMOTE_PLUGIN ssh
.
USE_NODE "node1.example.com"
USE_REMOTE_PLUGIN "ssh"
USE_SSH_USER "ubuntu"
USE_SSH_SUDO true
TEST "echo \"127.0.0.1 server1.example.com\" >> /etc/hosts"
USE_NODE "node1.example.com"
USE_REMOTE_PLUGIN "ssh"
USE_SSH_USER "ubuntu"
USE_SSH_SUDO true do
TEST "echo \"127.0.0.1 server1.example.com\" >> /etc/hosts"
end
# Run without sudo
TEST "stat ~/Public"
EXIT_ON_NOT_OK
By default, on error of a test case Test file execution is not terminated. Use this option to Halt the execution on error when required.
TEST "command 1"
# On setting this all future tests will use this setting
EXIT_ON_NOT_OK true
TEST "command 2"
# Only use this setting for some commands
EXIT_ON_NOT_OK true do
TEST "command 3"
TEST "command 4"
end
Embed other test files
Use load
keyword to include the tests/utilities from other files.
For example, repeat_tests.t
TEST "command 1"
TEST "command 2"
and the main.t
tests file
USE_REMOTE_PLUGIN "docker"
["node1.example.com", "node2.example.com", "node3.example.com"].each do |node|
USE_NODE node
load "./repeat_tests.t"
end
Note: Load path is relative to the current directory from where the binnacle
command is called.