diff --git a/gopls/integration/govim/Dockerfile b/gopls/integration/govim/Dockerfile new file mode 100644 index 0000000000..c3a0bde10c --- /dev/null +++ b/gopls/integration/govim/Dockerfile @@ -0,0 +1,16 @@ +# Copyright 2019 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +# govim requires a more recent version of vim than is available in most +# distros, so we build from their base image. +FROM govim/govim:go1.13.5_vim_v8.1.2414_v1 + +# Get a copy of govim in order to run its integration tests. We use a pinned +# version so that this build is repeatable, and so that we're not sensitive to +# test breakages in govim. +# TODO(findleyr): Once a version of govim has been tagged containing +# https://github.com/govim/govim/pull/629, switch this to @latest. +ENV GOPROXY=https://proxy.golang.org GOPATH=/go VIM_FLAVOR=vim +WORKDIR /src/mod +RUN go mod init mod && go get -t github.com/govim/govim@v0.0.27-0.20191220164001-63ce556bb69e diff --git a/gopls/integration/govim/README.md b/gopls/integration/govim/README.md new file mode 100644 index 0000000000..005ccffc70 --- /dev/null +++ b/gopls/integration/govim/README.md @@ -0,0 +1,27 @@ +# govim integration tests + +Files in this directory configure Cloud Build to run [govim] integration tests +against a gopls binary built from source. + +## Running on GCP + +To run these integration tests in Cloud Build (assuming the `gcloud` command is +configured for a valid GCP project): + +- `cd` to the root directory of the tools project. +- (at least once per GCP project) Build the test harness: +``` +$ gcloud builds submit --config=gopls/integration/govim/cloudbuild.harness.yaml +``` +- Run the integration tests: +``` +$ gcloud builds submit --config=gopls/integration/govim/cloudbuild.yaml +``` + +## Running locally + +Run `gopls/integration/govim/run_local.sh`. This may take a while the first +time it is run, as it will require building the test harness. Currently this +script assumes that docker may be executed without `sudo`. + +[govim]: https://github.com/govim/govim diff --git a/gopls/integration/govim/cloudbuild.harness.yaml b/gopls/integration/govim/cloudbuild.harness.yaml new file mode 100644 index 0000000000..974a66bf6a --- /dev/null +++ b/gopls/integration/govim/cloudbuild.harness.yaml @@ -0,0 +1,17 @@ +# Copyright 2019 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +# Build the govim test harness that will be used to run govim integration tests +# for gopls. See README.md for instructions on how to use this. +steps: + - name: 'gcr.io/cloud-builders/docker' + args: ['build', '-t', 'gcr.io/$PROJECT_ID/govim-harness', + # It is assumed that this build is running from the root directory of the + # tools repository. + '-f', 'gopls/integration/govim/Dockerfile', + # Use the integration test directory as build context: the test harness + # doesn't actually require any local files. + 'gopls/integration/govim'] +images: + - gcr.io/$PROJECT_ID/govim-harness diff --git a/gopls/integration/govim/cloudbuild.yaml b/gopls/integration/govim/cloudbuild.yaml new file mode 100644 index 0000000000..2cf2c7f7cb --- /dev/null +++ b/gopls/integration/govim/cloudbuild.yaml @@ -0,0 +1,23 @@ +# Copyright 2019 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +# Build gopls, and run the govim integration tests. See README.md for +# instructions on how to use this. +steps: + - name: 'golang:1.13' + env: ['GOPROXY=https://proxy.golang.org'] + dir: 'gopls' + args: ['go', 'build'] + - name: 'gcr.io/$PROJECT_ID/govim-harness' + # Work in the dummy module created in the test harness, that requires a + # pinned version of github.com/govim/govim. + dir: '/src/mod' + # The below setting currently causes too much noise on STDERR. + # TODO(findleyr): look into govim changes that make it easier to capture + # individual logs as build artifacts. + # env: ['GOVIM_TESTSCRIPT_STDERR=true'] + args: ['go', 'test', + 'github.com/govim/govim/cmd/govim', + # Specify the path to the gopls binary built in step 0. + '-gopls', '/workspace/gopls/gopls'] diff --git a/gopls/integration/govim/run_local.sh b/gopls/integration/govim/run_local.sh new file mode 100755 index 0000000000..35f3c8d8ee --- /dev/null +++ b/gopls/integration/govim/run_local.sh @@ -0,0 +1,31 @@ +#!/bin/bash -e + +# Run govim integration tests against a local gopls. +# TODO(findleyr): this script assumes that docker may be run without sudo. +# Update it to escalate privileges if and only if necessary. + +# Find the tools root, so that this script can be run from any directory. +script_dir=$(dirname "$(readlink -f "$0")") +tools_dir=$(readlink -f "${script_dir}/../../..") + +# Build gopls. +cd "${tools_dir}/gopls" +temp_gopls=$(mktemp -p "$PWD") +trap "rm -f \"${temp_gopls}\"" EXIT +go build -o "${temp_gopls}" + +# Build the test harness. Here we are careful to pass in a very limited build +# context so as to optimize caching. +cd "${tools_dir}" +docker build -t gopls-govim-harness -f gopls/integration/govim/Dockerfile \ + gopls/integration/govim + +# Run govim integration tests. +echo "running govim integration tests using ${temp_gopls}" +temp_gopls_name=$(basename "${temp_gopls}") +docker run --rm -t \ + -v "${tools_dir}:/src/tools" \ + -w "/src/mod" \ + gopls-govim-harness \ + go test github.com/govim/govim/cmd/govim \ + -gopls "/src/tools/gopls/${temp_gopls_name}"