mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2026-01-10 08:42:55 -05:00
Refactors test setup (#156)
* refactors test setup according to the postgres provider * updates readme for new test setup
This commit is contained in:
parent
e323be8f55
commit
62ddaf9e23
6 changed files with 113 additions and 84 deletions
|
|
@ -13,8 +13,14 @@ test: fmtcheck
|
|||
echo $(TEST) | \
|
||||
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
|
||||
|
||||
testacc_setup: fmtcheck
|
||||
@sh -c "'$(CURDIR)/scripts/testacc_setup.sh'"
|
||||
|
||||
testacc: fmtcheck
|
||||
@sh -c "'$(CURDIR)/scripts/runAccTests.sh'"
|
||||
@sh -c "'$(CURDIR)/scripts/testacc_full.sh'"
|
||||
|
||||
testacc_cleanup: fmtcheck
|
||||
@sh -c "'$(CURDIR)/scripts/testacc_cleanup.sh'"
|
||||
|
||||
compile: fmtcheck
|
||||
@sh -c "'$(CURDIR)/scripts/compile.sh'"
|
||||
|
|
|
|||
15
README.md
15
README.md
|
|
@ -62,9 +62,24 @@ In order to run the full suite of Acceptance tests, run `make testacc`.
|
|||
$ make testacc
|
||||
```
|
||||
|
||||
In order to run only single Acceptance tests, execute the following steps:
|
||||
|
||||
```sh
|
||||
# setup the testing environment
|
||||
$ make testacc_setup
|
||||
|
||||
# run single tests
|
||||
TF_LOG=INFO TF_ACC=1 go test -v ./docker -run ^TestAccDockerImage_data_private_config_file$ -timeout 360s
|
||||
|
||||
# cleanup the local testing resources
|
||||
$ make testacc_cleanup
|
||||
```
|
||||
|
||||
In order to extend the provider and test it with `terraform`, build the provider as mentioned above with
|
||||
```sh
|
||||
$ make build
|
||||
# or a specific version
|
||||
$ go build -o terraform-provider-docker_v1.2.0_x4
|
||||
```
|
||||
|
||||
Remove an explicit version of the provider you develop, because `terraform` will fetch
|
||||
|
|
|
|||
|
|
@ -1,83 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
log() {
|
||||
echo "####################"
|
||||
echo "## -> $1 "
|
||||
echo "####################"
|
||||
}
|
||||
|
||||
setup() {
|
||||
# Create self signed certs
|
||||
mkdir -p "$(pwd)"/scripts/testing/certs
|
||||
openssl req \
|
||||
-newkey rsa:2048 \
|
||||
-nodes \
|
||||
-x509 \
|
||||
-days 365 \
|
||||
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=127.0.0.1" \
|
||||
-keyout "$(pwd)"/scripts/testing/certs/registry_auth.key \
|
||||
-out "$(pwd)"/scripts/testing/certs/registry_auth.crt
|
||||
# Create auth
|
||||
mkdir -p "$(pwd)"/scripts/testing/auth
|
||||
# Start registry
|
||||
docker run --rm --entrypoint htpasswd registry:2 -Bbn testuser testpwd > "$(pwd)"/scripts/testing/auth/htpasswd
|
||||
docker run -d -p 15000:5000 --rm --name private_registry \
|
||||
-v "$(pwd)"/scripts/testing/auth:/auth \
|
||||
-e "REGISTRY_AUTH=htpasswd" \
|
||||
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
|
||||
-e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \
|
||||
-v "$(pwd)"/scripts/testing/certs:/certs \
|
||||
-e "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry_auth.crt" \
|
||||
-e "REGISTRY_HTTP_TLS_KEY=/certs/registry_auth.key" \
|
||||
registry:2
|
||||
# wait a bit for travis...
|
||||
sleep 5
|
||||
# Login to private registry
|
||||
docker login -u testuser -p testpwd 127.0.0.1:15000
|
||||
# Build private images
|
||||
for i in $(seq 1 3); do
|
||||
docker build -t tftest-service --build-arg JS_FILE_PATH=server_v${i}.js "$(pwd)"/scripts/testing -f "$(pwd)"/scripts/testing/Dockerfile
|
||||
docker tag tftest-service 127.0.0.1:15000/tftest-service:v${i}
|
||||
docker push 127.0.0.1:15000/tftest-service:v${i}
|
||||
docker tag tftest-service 127.0.0.1:15000/tftest-service
|
||||
docker push 127.0.0.1:15000/tftest-service
|
||||
done
|
||||
# Remove images from host machine before starting the tests
|
||||
for i in $(docker images -aq 127.0.0.1:15000/tftest-service); do docker rmi -f "$i"; done
|
||||
}
|
||||
|
||||
run() {
|
||||
go clean -testcache
|
||||
TF_ACC=1 go test ./docker -v -timeout 120m
|
||||
|
||||
# for a single test comment the previous line and uncomment the next line
|
||||
#TF_LOG=DEBUG TF_ACC=1 go test -v ./docker -run ^TestAccDockerService_updateMultiplePropertiesConverge$ -timeout 360s
|
||||
|
||||
# keep the return value for the scripts to fail and clean properly
|
||||
return $?
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
echo "### unsetted env ###"
|
||||
for p in $(docker container ls -f 'name=private_registry' -q); do docker stop $p; done
|
||||
echo "### stopped private registry ###"
|
||||
rm -f "$(pwd)"/scripts/testing/auth/htpasswd
|
||||
rm -f "$(pwd)"/scripts/testing/certs/registry_auth.*
|
||||
echo "### removed auth and certs ###"
|
||||
for resource in "container" "volume"; do
|
||||
for r in $(docker $resource ls -f 'name=tftest-' -q); do docker $resource rm -f "$r"; done
|
||||
echo "### removed $resource ###"
|
||||
done
|
||||
for resource in "config" "secret" "network"; do
|
||||
for r in $(docker $resource ls -f 'name=tftest-' -q); do docker $resource rm "$r"; done
|
||||
echo "### removed $resource ###"
|
||||
done
|
||||
for i in $(docker images -aq 127.0.0.1:15000/tftest-service); do docker rmi -f "$i"; done
|
||||
echo "### removed service images ###"
|
||||
}
|
||||
|
||||
## main
|
||||
log "setup" && setup
|
||||
log "run" && run || (log "cleanup" && cleanup && exit 1)
|
||||
log "cleanup" && cleanup
|
||||
22
scripts/testacc_cleanup.sh
Executable file
22
scripts/testacc_cleanup.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
for p in $(docker container ls -f 'name=private_registry' -q); do docker stop $p; done
|
||||
echo "### stopped private registry ###"
|
||||
|
||||
rm -f "$(pwd)"/scripts/testing/auth/htpasswd
|
||||
rm -f "$(pwd)"/scripts/testing/certs/registry_auth.*
|
||||
echo "### removed auth and certs ###"
|
||||
|
||||
for resource in "container" "volume"; do
|
||||
for r in $(docker $resource ls -f 'name=tftest-' -q); do docker $resource rm -f "$r"; done
|
||||
echo "### removed $resource ###"
|
||||
done
|
||||
|
||||
for resource in "config" "secret" "network"; do
|
||||
for r in $(docker $resource ls -f 'name=tftest-' -q); do docker $resource rm "$r"; done
|
||||
echo "### removed $resource ###"
|
||||
done
|
||||
|
||||
for i in $(docker images -aq 127.0.0.1:15000/tftest-service); do docker rmi -f "$i"; done
|
||||
echo "### removed service images ###"
|
||||
29
scripts/testacc_full.sh
Executable file
29
scripts/testacc_full.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
log() {
|
||||
echo "####################"
|
||||
echo "## -> $1 "
|
||||
echo "####################"
|
||||
}
|
||||
|
||||
setup() {
|
||||
sh "$(pwd)"/scripts/testacc_setup.sh
|
||||
}
|
||||
|
||||
run() {
|
||||
go clean -testcache
|
||||
TF_ACC=1 go test ./docker -v -timeout 120m
|
||||
|
||||
# keep the return value for the scripts to fail and clean properly
|
||||
return $?
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
sh "$(pwd)"/scripts/testacc_cleanup.sh
|
||||
}
|
||||
|
||||
## main
|
||||
log "setup" && setup
|
||||
log "run" && run || (log "cleanup" && cleanup && exit 1)
|
||||
log "cleanup" && cleanup
|
||||
40
scripts/testacc_setup.sh
Executable file
40
scripts/testacc_setup.sh
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Create self signed certs
|
||||
mkdir -p "$(pwd)"/scripts/testing/certs
|
||||
openssl req \
|
||||
-newkey rsa:2048 \
|
||||
-nodes \
|
||||
-x509 \
|
||||
-days 365 \
|
||||
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=127.0.0.1" \
|
||||
-keyout "$(pwd)"/scripts/testing/certs/registry_auth.key \
|
||||
-out "$(pwd)"/scripts/testing/certs/registry_auth.crt
|
||||
# Create auth
|
||||
mkdir -p "$(pwd)"/scripts/testing/auth
|
||||
# Start registry
|
||||
docker run --rm --entrypoint htpasswd registry:2 -Bbn testuser testpwd > "$(pwd)"/scripts/testing/auth/htpasswd
|
||||
docker run -d -p 15000:5000 --rm --name private_registry \
|
||||
-v "$(pwd)"/scripts/testing/auth:/auth \
|
||||
-e "REGISTRY_AUTH=htpasswd" \
|
||||
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
|
||||
-e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \
|
||||
-v "$(pwd)"/scripts/testing/certs:/certs \
|
||||
-e "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry_auth.crt" \
|
||||
-e "REGISTRY_HTTP_TLS_KEY=/certs/registry_auth.key" \
|
||||
registry:2
|
||||
# wait a bit for travis...
|
||||
sleep 5
|
||||
# Login to private registry
|
||||
docker login -u testuser -p testpwd 127.0.0.1:15000
|
||||
# Build private images
|
||||
for i in $(seq 1 3); do
|
||||
docker build -t tftest-service --build-arg JS_FILE_PATH=server_v${i}.js "$(pwd)"/scripts/testing -f "$(pwd)"/scripts/testing/Dockerfile
|
||||
docker tag tftest-service 127.0.0.1:15000/tftest-service:v${i}
|
||||
docker push 127.0.0.1:15000/tftest-service:v${i}
|
||||
docker tag tftest-service 127.0.0.1:15000/tftest-service
|
||||
docker push 127.0.0.1:15000/tftest-service
|
||||
done
|
||||
# Remove images from host machine before starting the tests
|
||||
for i in $(docker images -aq 127.0.0.1:15000/tftest-service); do docker rmi -f "$i"; done
|
||||
Loading…
Reference in a new issue