docs/test/integration
Andrea Luzzardi 671ddc8feb integration tests: run with native/vfs by default.
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
2015-05-03 19:08:02 -07:00
..
testdata/build integration: Fix docker build API test 2015-04-16 18:41:30 -07:00
README.md Add note against using devicemapper as a storage driver to run the integration tests 2015-04-23 14:55:02 -07:00
affinities.bats travis: Lint test files (ensure they are not space indented) 2015-04-30 17:31:14 -07:00
api.bats travis: Lint test files (ensure they are not space indented) 2015-04-30 17:31:14 -07:00
constraints.bats store constaints and affinities in labels 2015-04-30 14:33:21 -07:00
dependency.bats Add Integration test for dependency filters 2015-04-30 20:37:53 +00:00
file-discovery.bats add the integration test for file discovery 2015-04-11 07:55:04 +07:00
helpers.bash integration tests: run with native/vfs by default. 2015-05-03 19:08:02 -07:00
main.bats add integration test for zookeeper discovery 2015-04-10 00:05:08 +07:00
port-filter.bats Fix integration tests for swarm_manage changes 2015-04-10 11:31:15 -07:00
version-and-gitcommit.bats integration: Rename vars to helpers. 2015-03-06 11:42:43 -08:00
zk-discovery.bats add integration test for zookeeper discovery 2015-04-10 00:05:08 +07:00

README.md

Swarm Integration Tests

Integration tests provide end-to-end testing of Swarm.

While unit tests verify the code is working as expected by relying on mocks and artificially created fixtures, integration tests actually use real docker engines and communicate with Swarm through the CLI.

Note that integration tests do not replace unit tests.

As a rule of thumb, code should be tested thoroughly with unit tests. Integration tests on the other hand are meant to test a specific feature end to end.

Integration tests are written in bash using the bats framework.

Running integration tests

Start by [installing] (https://github.com/sstephenson/bats#installing-bats-from-source) bats on your system.

In order to run all integration tests, pass bats the test path:

$ bats test/integration

Note: There are known issues running the integration tests using devicemapper as a storage driver, make sure that your docker daemon is using aufs if you want to successfully run the integration tests.

Writing integration tests

[helper functions] (https://github.com/docker/swarm/blob/master/test/integration/helpers.bash) are provided in order to facilitate writing tests.

#!/usr/bin/env bats

# This will load the helpers.
load helpers

@test "this is a simple test" {
	# start_docker will start a given number of engines:
	start_docker 2

	# The address of those engines is available through $HOSTS:
	run docker -H ${HOSTS[0]} info
	# "run" automatically populates $status, $output and $lines.
	# Please refer to bats documentation to find out more.
	[ "$status" -eq 0 ]

	# You can start multiple docker engines in the same test:
	start_docker 1
	# Their address will be *appended* to $HOSTS. Therefore, since this is the 3rd
	# engine started, its index will be 2:
	run docker -H ${HOSTS[2]} info  

	# Additional parameters can be passed to the docker daemon:
	start_docker 1 --label foo=bar

	# swarm_manage will start the swarm manager, preconfigured with all engines
	# previously started by start_engine:
	swarm_manage

	# You can talk with said manager by using the docker_swarm helper:
	run docker_swarm info
	[ "$status" -eq 0 ]
	[ "${lines[1]}"="Nodes: 4" ]
}

# teardown is called at the end of every test.
function teardown() {
	# This will stop the swarm manager:
	swarm_manage_cleanup

	# This will stop and remove all engines launched by the test:
	stop_docker
}