Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions internal/e2e/basic_test.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have conflicting feeling about this. I wonder if it's wise to keep both options?

Maybe we can help a bit by injecting the agent/queue bit in the yaml?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but my stance isn't very strong on this topic so I will approve

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import (

func TestBasicE2E(t *testing.T) {
ctx := t.Context()
tc := newTestCase(t, `
agents:
queue: {{.queue}}
steps:
- command: echo hello world
`)
tc := newTestCase(t, "basic_e2e.yaml")

tc.startAgent()
build := tc.triggerBuild()
Expand Down
4 changes: 4 additions & 0 deletions internal/e2e/fixtures/basic_e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
agents:
queue: "{{.queue}}"
steps:
- command: echo hello world
16 changes: 13 additions & 3 deletions internal/e2e/testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package e2e
import (
"cmp"
"context"
"embed"
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"slices"
"strconv"
Expand Down Expand Up @@ -50,6 +52,9 @@ type cleanupFn = func() error

func nopCleanup() error { return nil }

//go:embed fixtures
var fixturesFS embed.FS

// testCase bundles the information needed to run an end-to-end test.
// Note that it embeds testing.TB - each test should create its own testCase.
type testCase struct {
Expand All @@ -67,15 +72,20 @@ type testCase struct {
// It also registers cleanups with t.Cleanup so that the queue and pipeline
// are (usually) automatically deleted.
// It calls t.Fatal to end the test early if there was a failure setting up.
func newTestCase(t testing.TB, pipelineConfigTemplate string) *testCase {
func newTestCase(t testing.TB, file string) *testCase {
t.Helper()
ctx := t.Context()

name := strings.ToLower(t.Name() + "-" + jobID)

tmpl, err := template.New("pipeline").Parse(pipelineConfigTemplate)
pipelineCfgTmpl, err := fixturesFS.ReadFile(path.Join("fixtures", file))
if err != nil {
t.Fatalf("fixturesFS.ReadFile(%q) error = %v", file, err)
}

tmpl, err := template.New("pipeline").Parse(string(pipelineCfgTmpl))
if err != nil {
t.Fatalf("template.New(pipeline).Parse(%q) error = %v", pipelineConfigTemplate, err)
t.Fatalf("template.New(pipeline).Parse(%q) error = %v", pipelineCfgTmpl, err)
}

client, err := buildkite.NewClient(
Expand Down