"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

How to perform integration testing in Go?

2020-09-29

Categories: DevOps Programming

Integration testing can be triggered by using Drone downstream plugin:

steps:
- name: trigger
  image: plugins/downstream:linux-amd64
  settings:
    params:
    - COMMIT_BRANCH=${DRONE_COMMIT_BRANCH}
    repositories:
    - repo/integration-test@${DRONE_COMMIT_BRANCH}
    server: https://drone.example.com
    token:
      from_secret: drone_token

It can be separated with unit tests by using build tags:

// +build integration

package webserver_test

Then we can write code to perform integration test as usual.

In the integration-test, clone the upstream repo:

- name: clone-upstream
  image: alpine/git:v2.24.3
  commands:
  - git clone -b $${COMMIT_BRANCH:-main} https://github.com/owner/upstream.git /upstream
  volumes:
  - name: upstream
    path: /upstream

and run integration tests:

- name: test-something
  image: golang:1.14.7
  commands:
  - cd /path/to/webserver
  - go test -tags integration -v -run TestSomething
  volumes:
  - name: upstream
    path: /upstream

Tags: golang drone integration-test

Edit on GitHub

Related Posts: