From b55643a0eba6c0ff06df64fcbb652f87efd441bc Mon Sep 17 00:00:00 2001 From: Ben Moskovitz Date: Wed, 10 Apr 2024 09:17:40 +1000 Subject: [PATCH] Add integration test ensuring that cache paths are passed to the bootstrap correctly --- .../job_environment_integration_test.go | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 agent/integration/job_environment_integration_test.go diff --git a/agent/integration/job_environment_integration_test.go b/agent/integration/job_environment_integration_test.go new file mode 100644 index 0000000000..ef4ae47190 --- /dev/null +++ b/agent/integration/job_environment_integration_test.go @@ -0,0 +1,48 @@ +package integration + +import ( + "context" + "testing" + + "github.com/buildkite/agent/v3/agent" + "github.com/buildkite/agent/v3/api" + "github.com/buildkite/bintest/v3" + "github.com/buildkite/go-pipeline" +) + +func TestWhenCachePathsSetInJobStep_CachePathsEnvVarIsSet(t *testing.T) { + t.Parallel() + + ctx := context.Background() + job := &api.Job{ + ID: "my-job-id", + ChunksMaxSizeBytes: 1024, + Step: pipeline.CommandStep{ + Cache: &pipeline.Cache{ + Paths: []string{"foo", "bar"}, + }, + }, + } + + mb := mockBootstrap(t) + defer mb.CheckAndClose(t) + + mb.Expect().Once().AndExitWith(0).AndCallFunc(func(c *bintest.Call) { + if got, want := c.GetEnv("BUILDKITE_AGENT_CACHE_PATHS"), "foo,bar"; got != want { + t.Errorf("c.GetEnv(BUILDKITE_AGENT_CACHE_PATHS) = %q, want %q", got, want) + } + c.Exit(0) + }) + + // create a mock agent API + e := createTestAgentEndpoint() + server := e.server("my-job-id") + defer server.Close() + + runJob(t, ctx, testRunJobConfig{ + job: job, + server: server, + agentCfg: agent.AgentConfiguration{}, + mockBootstrap: mb, + }) +}