How to perform integration testing in Go?
2020-09-29
Categories: DevOps Programming
Integration testing can be triggered by using Drone downstream plugin:
1steps: 2- name: trigger 3 image: plugins/downstream:linux-amd64 4 settings: 5 params: 6 - COMMIT_BRANCH=${DRONE_COMMIT_BRANCH} 7 repositories: 8 - repo/integration-test@${DRONE_COMMIT_BRANCH} 9 server: https://drone.example.com 10 token: 11 from_secret: drone_token
It can be separated with unit tests by using build tags:
1// +build integration 2 3package webserver_test
Then we can write code to perform integration test as usual.
In the integration-test, clone the upstream repo:
1- name: clone-upstream 2 image: alpine/git:v2.24.3 3 commands: 4 - git clone -b $${COMMIT_BRANCH:-main} https://github.com/owner/upstream.git /upstream 5 volumes: 6 - name: upstream 7 path: /upstream
and run integration tests:
1- name: test-something 2 image: golang:1.14.7 3 commands: 4 - cd /path/to/webserver 5 - go test -tags integration -v -run TestSomething 6 volumes: 7 - name: upstream 8 path: /upstream
Tags: golang drone integration-test
Related Posts:
- gocloud - writing data to a bucket: 403
- Terraform failed to acquire state lock: 403: Access denied., forbidden
- The King of Vietnamese language game show
- How to run a pipeline step only when pushing to a new branch?
- How to add full text search to my static website?