docs/test/integration
Nishant Totla 1675c4ca85 Merge pull request #2271 from abronan/fix_leader_election_test
integration: increase retry for leader election store failure test
2016-06-14 14:17:30 -07:00
..
api show container status of each node in docker info 2016-05-04 17:23:45 +08:00
compose use env in compose test 2016-02-24 17:01:54 -08:00
discovery Remove internal retry in discovery_check_swarm_info because caller retries are already in place. 2016-02-29 13:48:59 -08:00
mesos Update stats test to stop connection 2016-04-29 17:58:52 -07:00
nodemanagement Fixing integration tests 2016-04-14 09:37:01 -07:00
testdata use env in compose test 2016-02-24 17:01:54 -08:00
Dockerfile rollback to Go 1.5.4 2016-04-23 01:50:10 -07:00
README.md Teardown function needs to be declared before tests. 2016-04-15 15:50:02 +12:00
affinities.bats Printing entire set of unsatisfiable constraints for container scheduling 2016-03-14 17:17:06 -07:00
api_version.bats fix api_version test 2015-06-30 11:48:08 -07:00
build_with_filters.bats Filter for containerslots-label 2016-05-03 09:54:51 -07:00
cli.bats integration: cleanup debug echo and test names 2015-05-06 15:47:28 -07:00
cli_join.bats make port 0 invalid in checkAddrFormat 2016-03-30 19:47:42 +08:00
cli_list.bats validate duration flags:--delay, --timeout,--replication-ttl 2016-03-16 10:09:57 +08:00
constraints.bats fix soft filter 2015-10-08 05:16:19 -04:00
containerslots-filter.bats Carry over pr/2137 with minor updates. 2016-05-03 14:29:38 -07:00
dependency.bats merge volumes-from integration tests 2015-05-16 08:22:17 +08:00
helpers.bash update compose, remove useless bash and improve test 2016-04-14 14:20:01 -07:00
port-filters.bats Printing entire set of unsatisfiable constraints for container scheduling 2016-03-14 17:17:06 -07:00
replication.bats integration: increase retry for leader election store failure test 2016-05-24 10:30:56 -07:00
rescheduling.bats add even more tests on rescheduling 2016-02-26 02:00:06 -08:00
resource_management.bats use --cpu-shares instead of -c in integration test 2016-05-04 00:12:58 +08:00
run.sh upgrade integration environment 2015-11-22 15:31:57 -08:00
swarm_id.bats swarm IDs: Convert Swarm ID to Container ID in API Proxy. 2015-05-11 16:56:08 -07:00
test_runner.sh fix swarm build in tests 2016-04-26 11:16:37 -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

The easiest way to run integration tests is with Docker:

$ test/integration/run.sh

Alternatively, you can run integration tests directly on your host:

$ bats test/integration

In order to do that, you will need to setup a full development environment plus bats

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

# 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
}

@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" ]
}