Skip to content

Commit c9ca995

Browse files
authored
Merge pull request #3599 from buildkite/pb-968-create-a-testing-framework
Add end-to-end testing infra
2 parents c1039ae + 4167772 commit c9ca995

File tree

10 files changed

+397
-3
lines changed

10 files changed

+397
-3
lines changed

.buildkite/Dockerfile-e2e

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM public.ecr.aws/docker/library/golang:1.24.10@sha256:7b13449f08287fdb53114d65bdf20eb3965e4e54997903b5cb9477df0ea37c12

.buildkite/docker-compose.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.5'
2-
31
services:
42
lint:
53
build:
@@ -32,6 +30,23 @@ services:
3230
- GOMODCACHE=/gomodcache
3331
- BUILDKITE_TEST_ENGINE_API_ACCESS_TOKEN
3432

33+
e2e:
34+
build:
35+
context: .
36+
dockerfile: Dockerfile-e2e
37+
volumes:
38+
- ../:/work:cached
39+
working_dir: /work
40+
environment:
41+
- BUILDKITE_BUILD_NUMBER
42+
- BUILDKITE_JOB_ID
43+
- BUILDKITE_BUILD_CREATOR_EMAIL
44+
- BUILDKITE_BUILD_CREATOR
45+
- CI_E2E_TESTS_BUILDKITE_API_TOKEN
46+
- CI_E2E_TESTS_AGENT_TOKEN
47+
- CI_E2E_TESTS_TARGET_ORG
48+
- CI_E2E_TESTS_TARGET_CLUSTER
49+
3550
ruby:
3651
image: ruby:2.7.6
3752
volumes:

.buildkite/pipeline.e2e.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
agents:
2+
queue: agent-runners-linux-amd64
3+
4+
env:
5+
CI_E2E_TESTS_TARGET_ORG: agent-e2e-testing
6+
CI_E2E_TESTS_TARGET_CLUSTER: e1773a06-b43c-4b77-84e5-5e088a737f6a
7+
8+
steps:
9+
- label: ":go::sleuth_or_spy: Run agent end-to-end tests"
10+
command: .buildkite/steps/e2e-tests.sh
11+
secrets:
12+
- CI_E2E_TESTS_BUILDKITE_API_TOKEN
13+
- CI_E2E_TESTS_AGENT_TOKEN
14+
plugins:
15+
- docker-compose#v4.14.0:
16+
config: .buildkite/docker-compose.yml
17+
cli-version: 2
18+
mount-buildkite-agent: true
19+
run: e2e

.buildkite/steps/e2e-tests.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# TODO: download the agent to test as an artifact
5+
#buildkite-agent artifact download buildkite-agent . --build "${BUILDKITE_TRIGGERED_FROM_BUILD_ID}"
6+
#export CI_E2E_TESTS_AGENT_PATH="${PWD}/buildkite-agent"
7+
8+
# For now, e2e test the agent that's currently running
9+
export CI_E2E_TESTS_AGENT_PATH="$(which buildkite-agent)"
10+
go test -v -tags e2e ./internal/e2e/... | sed -e 's/^/> /'

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/aws/smithy-go v1.24.0
2222
github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20220812150832-b6b31c6eeeaf
2323
github.com/buildkite/bintest/v3 v3.3.0
24+
github.com/buildkite/go-buildkite/v4 v4.11.0
2425
github.com/buildkite/go-pipeline v0.16.0
2526
github.com/buildkite/interpolate v0.1.5
2627
github.com/buildkite/roko v1.4.0
@@ -112,6 +113,7 @@ require (
112113
github.com/bitfield/gotestdox v0.2.2 // indirect
113114
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
114115
github.com/buildkite/test-engine-client v1.6.0 // indirect
116+
github.com/cenkalti/backoff v1.1.1-0.20171020064038-309aa717adbf // indirect
115117
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
116118
github.com/cespare/xxhash/v2 v2.3.0 // indirect
117119
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20220812150832-b6b31c6eeeaf
132132
github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20220812150832-b6b31c6eeeaf/go.mod h1:CeKhh8xSs3WZAc50xABMxu+FlfAAd5PNumo7NfOv7EE=
133133
github.com/buildkite/bintest/v3 v3.3.0 h1:RTWcSaJRlOT6t/K311ejPf+0J3LE/QEODzVG3vlLnWo=
134134
github.com/buildkite/bintest/v3 v3.3.0/go.mod h1:btqpTsVODiJcb0NMdkkmtMQ6xoFc2W/nY5yy+3I0zcs=
135+
github.com/buildkite/go-buildkite/v4 v4.11.0 h1:rEvvUwITrqv433W9JWf6mj+NkkcM45s+ObhNs6C17i4=
136+
github.com/buildkite/go-buildkite/v4 v4.11.0/go.mod h1:DlebrRJqpZttXDjCW+MJ1QyW9AN++ZWt/UbPtKdbSSk=
135137
github.com/buildkite/go-pipeline v0.16.0 h1:wEgWUMRAgSg1ZnWOoA3AovtYYdTvN0dLY1zwUWmPP+4=
136138
github.com/buildkite/go-pipeline v0.16.0/go.mod h1:VE37qY3X5pmAKKUMoDZvPsHOQuyakB9cmXj9Qn6QasA=
137139
github.com/buildkite/interpolate v0.1.5 h1:v2Ji3voik69UZlbfoqzx+qfcsOKLA61nHdU79VV+tPU=
@@ -144,6 +146,8 @@ github.com/buildkite/test-engine-client v1.6.0 h1:yk/gdkFFU8B1+M16mxPNmxJgVoYffI
144146
github.com/buildkite/test-engine-client v1.6.0/go.mod h1:J6LrqenaJPfVCffiWW1/QxjICFb+OkqCvdCd7qAI0AE=
145147
github.com/buildkite/zstash v0.5.0 h1:e70mf8U2EjEB1eixXR78s6bsLgfo6bWLisVlRv58wCI=
146148
github.com/buildkite/zstash v0.5.0/go.mod h1:h70JfAEa2Ys1GDQQ6CNoKIMfMgJ0LZkNmQnzK710PHQ=
149+
github.com/cenkalti/backoff v1.1.1-0.20171020064038-309aa717adbf h1:yxlp0s+Sge9UsKEK0Bsvjiopb9XRk+vxylmZ9eGBfm8=
150+
github.com/cenkalti/backoff v1.1.1-0.20171020064038-309aa717adbf/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
147151
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
148152
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
149153
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=

internal/e2e/basic_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build e2e
2+
3+
package e2e
4+
5+
import "testing"
6+
7+
func TestBasicE2E(t *testing.T) {
8+
ctx := t.Context()
9+
tc := newTestCase(t, `
10+
agents:
11+
queue: {{.queue}}
12+
steps:
13+
- command: echo hello world
14+
`)
15+
16+
tc.startAgent()
17+
18+
build := tc.triggerBuild()
19+
state, err := tc.waitForBuild(ctx, build)
20+
if err != nil {
21+
t.Fatalf("tc.waitForBuild(build %s) error = %v", build.ID, err)
22+
}
23+
if got, want := state, "passed"; got != want {
24+
t.Errorf("Build state = %q, want %q", got, want)
25+
}
26+
27+
// TODO: add ability to inspect job logs
28+
}

internal/e2e/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Package e2e holds the end-to-end tests and test framework.
2+
// Test files are tagged go:build e2e so they are not run by default
3+
// (e.g. with plain `go test ./...`).
4+
package e2e

0 commit comments

Comments
 (0)