implement volume mount for container job (#1101)
* implement volume mount for container job * Update pkg/runner/run_context.go Co-authored-by: Ryan <me@hackerc.at> * add tests for container volume mount options * remove unused code * prefer if-else instead of if-continue * remove continue * add some tests Co-authored-by: Ryan <me@hackerc.at> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
@@ -293,6 +293,44 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("ContainerVolumeMountTest", func(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
volumes []string
|
||||
wantbind string
|
||||
wantmount map[string]string
|
||||
}{
|
||||
{"BindAnonymousVolume", []string{"/volume"}, "/volume", map[string]string{}},
|
||||
{"BindHostFile", []string{"/path/to/file/on/host:/volume"}, "/path/to/file/on/host:/volume", map[string]string{}},
|
||||
{"MountExistingVolume", []string{"volume-id:/volume"}, "", map[string]string{"volume-id": "/volume"}},
|
||||
}
|
||||
|
||||
for _, testcase := range tests {
|
||||
t.Run(testcase.name, func(t *testing.T) {
|
||||
job := &model.Job{}
|
||||
err := job.RawContainer.Encode(map[string][]string{
|
||||
"volumes": testcase.volumes,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
rc := rctemplate.Clone()
|
||||
rc.Run.JobID = "job1"
|
||||
rc.Run.Workflow.Jobs = map[string]*model.Job{"job1": job}
|
||||
|
||||
gotbind, gotmount := rc.GetBindsAndMounts()
|
||||
|
||||
if len(testcase.wantbind) > 0 {
|
||||
assert.Contains(t, gotbind, testcase.wantbind)
|
||||
}
|
||||
|
||||
for k, v := range testcase.wantmount {
|
||||
assert.Contains(t, gotmount, k)
|
||||
assert.Equal(t, gotmount[k], v)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetGitHubContext(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user