mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
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
This commit is contained in:
parent
a197fea4ba
commit
10c26c53a3
1 changed files with 27 additions and 24 deletions
|
@ -794,21 +794,16 @@ jobs:
|
||||||
},
|
},
|
||||||
inputs: []container.NewContainerInput{
|
inputs: []container.NewContainerInput{
|
||||||
{
|
{
|
||||||
Name: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB",
|
Name: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB",
|
||||||
Image: "some:image",
|
Image: "some:image",
|
||||||
Username: "containerusername",
|
Username: "containerusername",
|
||||||
Password: "containerpassword",
|
Password: "containerpassword",
|
||||||
Entrypoint: []string{"tail", "-f", "/dev/null"},
|
Entrypoint: []string{"tail", "-f", "/dev/null"},
|
||||||
Cmd: nil,
|
Cmd: nil,
|
||||||
WorkingDir: "/my/workdir",
|
WorkingDir: "/my/workdir",
|
||||||
Env: []string{},
|
Env: []string{},
|
||||||
ToolCache: "/opt/hostedtoolcache",
|
ToolCache: "/opt/hostedtoolcache",
|
||||||
Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"},
|
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",
|
|
||||||
Privileged: false,
|
Privileged: false,
|
||||||
UsernsMode: "",
|
UsernsMode: "",
|
||||||
Platform: "",
|
Platform: "",
|
||||||
|
@ -817,11 +812,6 @@ jobs:
|
||||||
PortBindings: nil,
|
PortBindings: nil,
|
||||||
ConfigOptions: "",
|
ConfigOptions: "",
|
||||||
JobOptions: "",
|
JobOptions: "",
|
||||||
ValidVolumes: []string{
|
|
||||||
"WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB",
|
|
||||||
"WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB-env",
|
|
||||||
"/var/run/docker.sock",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca49599-fe7f4c0058dbd2161ebe4aafa71cd83bd96ee19d3ca8043d5e4bc477a664a80c",
|
Name: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca49599-fe7f4c0058dbd2161ebe4aafa71cd83bd96ee19d3ca8043d5e4bc477a664a80c",
|
||||||
|
@ -834,8 +824,6 @@ jobs:
|
||||||
Env: []string{},
|
Env: []string{},
|
||||||
ToolCache: "/opt/hostedtoolcache",
|
ToolCache: "/opt/hostedtoolcache",
|
||||||
Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"},
|
Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"},
|
||||||
Mounts: map[string]string{},
|
|
||||||
NetworkMode: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB-job-network",
|
|
||||||
Privileged: false,
|
Privileged: false,
|
||||||
UsernsMode: "",
|
UsernsMode: "",
|
||||||
Platform: "",
|
Platform: "",
|
||||||
|
@ -856,8 +844,6 @@ jobs:
|
||||||
Env: []string{},
|
Env: []string{},
|
||||||
ToolCache: "/opt/hostedtoolcache",
|
ToolCache: "/opt/hostedtoolcache",
|
||||||
Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"},
|
Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"},
|
||||||
Mounts: map[string]string{},
|
|
||||||
NetworkMode: "WORKFLOW-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_JOB-job-network",
|
|
||||||
Privileged: false,
|
Privileged: false,
|
||||||
UsernsMode: "",
|
UsernsMode: "",
|
||||||
Platform: "",
|
Platform: "",
|
||||||
|
@ -890,7 +876,24 @@ jobs:
|
||||||
|
|
||||||
require.NoError(t, rc.prepareJobContainer(ctx))
|
require.NoError(t, rc.prepareJobContainer(ctx))
|
||||||
slices.SortFunc(containerInputs, func(a, b container.NewContainerInput) int { return cmp.Compare(a.Username, b.Username) })
|
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++ {
|
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)
|
assert.EqualValues(t, testCase.inputs[i], containerInputs[i], containerInputs[i].Username)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue