I’m working on a program which interacts with Consul. Consul is relatively simple to run locally, it’s just a static binary with minimal config necessary, so I was considering launching an instance when running tests, to allow tests to pass that interact with the API.
Thoughts? how do you normally setup an environment for integration tests?
What I’m going to go with is using build tags, as suggested in this post (in “Testing and Validation”). Basically I’ll create files containing integration tests using a format such as something_integration_test.go. At the top of those files I’ll have // +build integration.
I can then run all tests using: go test -tags=integration ./... or I can exclude integration tests by just running go test ./...
I am using a Makefile to run my tests which will setup and launch Consul (an external service needed by some tests):
consul:
@yumdownloader consul
@rpm2cpio consul-0.5.2.rpm | cpio -idmv
@rm -rf /tmp/{tmp,raft,serf}
@./consul/consul agent -server -bootstrap --data-dir=/tmp --ui-dir=consul/dist &
@sleep 5
itest: consul
@go test -tags=integration ./...