Run integration tests

I have some Postman collection that I want to run as integration test using drone. I am going to be using newman cli tool for Postman. How can I set up my rest API as a service in Drone?

My restful API is written in Go. I am already able to run unit test in drone. This is what my drone.yml looks like. I removed the publish and deploy pipelines for brevity.

kind: pipeline
type: kubernetes
name: Test

trigger:
  event:
    - push

node_selector:
  type: cicd

steps:
  - name: test
    image: golang:1.14-alpine
    pull: always
    environment:
      SSH_KEY:
        from_secret: SSH_KEY
    commands:
      - |
        apk add -U git
        mkdir /root/.ssh
        echo -n "$SSH_KEY" > /root/.ssh/id_rsa
        chmod 600 /root/.ssh/id_rsa
        export CGO_ENABLED=0
        go generate ./...
        go test ./...
        go build ./...

Similar question:


Drone supports services [1] which are background containers that can be used for integration testing (mysql, redis, etc). You can also define services inline [2] in your pipeline steps to control order of operations and, such as your case, even use your own source code as a service.

Here is an example to demonstrate an inline service (replace with your Go program):

kind: pipeline
type: docker
name: default

steps:
- name: build
  image: golang:1.15
  commands:
  - go build -o my-app

- name: app
  image: golang:1.15
  detach: true
  commands:
  - ./my-app

- name: curl
  image: golang:1.15
  commands:
  - sleep 5
  - curl http://app:8080

[1] https://docs.drone.io/pipeline/kubernetes/syntax/services/
[2] https://docs.drone.io/pipeline/kubernetes/syntax/services/#detached-steps

Thank you! I will try this out!