2.10 Golang library testing example

You can run the tests for a Golang library across any specified versions.

This example shows how to have multiple versions of a language, environment, or dependency fetched and integrated in to a Pipeline.

For these Docker images, defining them as Resources has two advantages for this use case. First, this enables the pipeline to be triggered when there are new versions of those images available. Second, referencing them in the task's task step image param is helpful as it will ensure consistency between the image versions fetched by the Resource and the image version running in the job.

Pipeline Configuration

---
resources:
- name: golang-mock-git
  type: git
  icon: github
  source:
    uri: https://github.com/golang/mock.git

- name: golang-1.11.x-image
  type: registry-image
  icon: docker
  source:
    repository: golang
    tag: 1.11-stretch

- name: golang-1.12.x-image
  type: registry-image
  icon: docker
  source:
    repository: golang
    tag: 1.12-stretch

- name: golang-1.13.x-image
  type: registry-image
  icon: docker
  source:
    repository: golang
    tag: 1.13-stretch

task-config: &task-config
  platform: linux
  inputs:
    - name: golang-mock-git
      path: go/src/github.com/golang/mock
  params:
    GO111MODULE: "on"
  run:
    path: /bin/sh
    args:
      - -c
      - |
        GOPATH=$PWD/go

        cd go/src/github.com/golang/mock

        go vet ./...
        go build ./...
        go install github.com/golang/mock/mockgen
        GO111MODULE=off go get -u golang.org/x/lint/golint
        ./ci/check_go_fmt.sh
        ./ci/check_go_lint.sh
        ./ci/check_go_generate.sh
        ./ci/check_go_mod.sh
        go test -v ./...

jobs:
- name: golang-1.11
  public: true
  plan:
    - get: golang-mock-git
      trigger: true
    - get: golang-1.11.x-image
      trigger: true
    - task: run-tests
      image: golang-1.11.x-image
      config:
        << : *task-config
- name: golang-1.12
  public: true
  plan:
    - get: golang-mock-git
      trigger: true
    - get: golang-1.12.x-image
      trigger: true
    - task: run-tests
      image: golang-1.12.x-image
      config:
        << : *task-config
- name: golang-1.13
  public: true
  plan:
    - get: golang-mock-git
      trigger: true
    - get: golang-1.13.x-image
      trigger: true
    - task: run-tests
      image: golang-1.13.x-image
      config:
        << : *task-config

References