From 0ab50520389dc7b00e46156ebdfc750a9dff4e18 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Mon, 28 Oct 2024 19:56:56 +0000 Subject: [PATCH] chore(integration): update TestLogs to validate that CODER_ASGENT_SUBSYSTEM is set correctly (#397) (cherry picked from commit 561cc53d791cb7dcd5caa1edc66217f40c49204c) --- integration/integration_test.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/integration/integration_test.go b/integration/integration_test.go index 9413c34..bb900a0 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -123,10 +123,11 @@ func TestLogs(t *testing.T) { "Dockerfile": fmt.Sprintf(`FROM %s`, testImageUbuntu), }, }) - _, err := runEnvbuilder(t, runOpts{env: []string{ + ctrID, err := runEnvbuilder(t, runOpts{env: []string{ envbuilderEnv("GIT_URL", srv.URL), "CODER_AGENT_URL=" + logSrv.URL, "CODER_AGENT_TOKEN=" + token, + "ENVBUILDER_INIT_SCRIPT=env", }}) require.NoError(t, err) ctx, cancel := context.WithTimeout(context.Background(), time.Minute) @@ -136,6 +137,28 @@ func TestLogs(t *testing.T) { t.Fatal("timed out waiting for logs") case <-logsDone: } + + // Wait for the container to exit + client, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + require.NoError(t, err) + require.Eventually(t, func() bool { + status, err := client.ContainerInspect(ctx, ctrID) + if !assert.NoError(t, err) { + return false + } + return !status.State.Running + }, 10*time.Second, time.Second, "container never exited") + + // Check the expected log output + logReader, err := client.ContainerLogs(ctx, ctrID, container.LogsOptions{ + ShowStdout: true, + ShowStderr: true, + }) + require.NoError(t, err) + logBytes, err := io.ReadAll(logReader) + require.NoError(t, err) + logs := string(logBytes) + require.Contains(t, logs, "CODER_AGENT_SUBSYSTEM=envbuilder") } func TestInitScriptInitCommand(t *testing.T) {