From 10c26c53a3904f58230d1c188546acbf772343d1 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Thu, 14 Aug 2025 11:14:20 +0200 Subject: [PATCH] chore: do not hardcode names in TestRunContext_PrepareJobContainer Replace asserting hard coded names with assertions on how the services and the job container relate. It slightly improves logic coverage and makes the test insensitive to how network and volume names are created. - compare the network names of the services and the job container to be equal, demonstrating they can communicate - verify the mounts and valid volumes of services to be empty - verify the internal mounts of the job container to be valid volumes --- act/runner/run_context_test.go | 51 ++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/act/runner/run_context_test.go b/act/runner/run_context_test.go index d03a1b72..296afd1b 100644 --- a/act/runner/run_context_test.go +++ b/act/runner/run_context_test.go @@ -794,21 +794,16 @@ jobs: }, inputs: []container.NewContainerInput{ { - Name: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB", - Image: "some:image", - Username: "containerusername", - Password: "containerpassword", - Entrypoint: []string{"tail", "-f", "/dev/null"}, - Cmd: nil, - WorkingDir: "/my/workdir", - Env: []string{}, - ToolCache: "/opt/hostedtoolcache", - Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"}, - Mounts: map[string]string{ - "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB": "/my/workdir", - "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB-env": "/var/run/act", - }, - NetworkMode: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB-job-network", + Name: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB", + Image: "some:image", + Username: "containerusername", + Password: "containerpassword", + Entrypoint: []string{"tail", "-f", "/dev/null"}, + Cmd: nil, + WorkingDir: "/my/workdir", + Env: []string{}, + ToolCache: "/opt/hostedtoolcache", + Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"}, Privileged: false, UsernsMode: "", Platform: "", @@ -817,11 +812,6 @@ jobs: PortBindings: nil, ConfigOptions: "", JobOptions: "", - ValidVolumes: []string{ - "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB", - "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB-env", - "/var/run/docker.sock", - }, }, { Name: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca49599-fe7f4c0058dbd2161ebe4aafa71cd83bd96ee19d3ca8043d5e4bc477a664a80c", @@ -834,8 +824,6 @@ jobs: Env: []string{}, ToolCache: "/opt/hostedtoolcache", Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"}, - Mounts: map[string]string{}, - NetworkMode: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB-job-network", Privileged: false, UsernsMode: "", Platform: "", @@ -856,8 +844,6 @@ jobs: Env: []string{}, ToolCache: "/opt/hostedtoolcache", Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"}, - Mounts: map[string]string{}, - NetworkMode: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB-job-network", Privileged: false, UsernsMode: "", Platform: "", @@ -890,7 +876,24 @@ jobs: require.NoError(t, rc.prepareJobContainer(ctx)) slices.SortFunc(containerInputs, func(a, b container.NewContainerInput) int { return cmp.Compare(a.Username, b.Username) }) + jobContainerInput := containerInputs[0] + require.Equal(t, "containerusername", jobContainerInput.Username) + require.NotEmpty(t, jobContainerInput.NetworkMode) + for source := range jobContainerInput.Mounts { + assert.Contains(t, jobContainerInput.ValidVolumes, source) + } for i := 0; i < len(containerInputs); i++ { + + assert.Equal(t, jobContainerInput.NetworkMode, containerInputs[i].NetworkMode, containerInputs[i].Username) + containerInputs[i].NetworkMode = "" + + if strings.HasPrefix(containerInputs[i].Username, "service") { + assert.Empty(t, containerInputs[i].Mounts) + assert.Empty(t, containerInputs[i].ValidVolumes) + } + containerInputs[i].Mounts = nil + containerInputs[i].ValidVolumes = nil + assert.EqualValues(t, testCase.inputs[i], containerInputs[i], containerInputs[i].Username) } })