MCPcopy
hub / github.com/tuna/tunasync / TestRsyncProviderWithDocker

Function TestRsyncProviderWithDocker

worker/provider_test.go:274–344  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

272}
273
274func TestRsyncProviderWithDocker(t *testing.T) {
275 Convey("Rsync in Docker should work", t, func() {
276 tmpDir, err := os.MkdirTemp("", "tunasync")
277 defer os.RemoveAll(tmpDir)
278 So(err, ShouldBeNil)
279 scriptFile := filepath.Join(tmpDir, "myrsync")
280 excludeFile := filepath.Join(tmpDir, "exclude.txt")
281
282 g := &Config{
283 Global: globalConfig{
284 Retry: 2,
285 },
286 Docker: dockerConfig{
287 Enable: true,
288 Volumes: []string{
289 scriptFile + ":/bin/myrsync",
290 "/etc/gai.conf:/etc/gai.conf:ro",
291 },
292 },
293 }
294 c := mirrorConfig{
295 Name: "tuna",
296 Provider: provRsync,
297 Upstream: "rsync://rsync.tuna.moe/tuna/",
298 Command: "/bin/myrsync",
299 ExcludeFile: excludeFile,
300 DockerImage: "alpine:3.23",
301 LogDir: tmpDir,
302 MirrorDir: tmpDir,
303 UseIPv6: true,
304 Timeout: 100,
305 Interval: 600,
306 }
307
308 provider := newMirrorProvider(c, g)
309
310 So(provider.Type(), ShouldEqual, provRsync)
311 So(provider.Name(), ShouldEqual, c.Name)
312 So(provider.WorkingDir(), ShouldEqual, c.MirrorDir)
313 So(provider.LogDir(), ShouldEqual, c.LogDir)
314
315 cmdScriptContent := `#!/bin/sh
316#echo "$@"
317while [[ $# -gt 0 ]]; do
318if [[ "$1" = "--exclude-from" ]]; then
319 cat "$2"
320 shift
321fi
322shift
323done
324`
325 err = os.WriteFile(scriptFile, []byte(cmdScriptContent), 0755)
326 So(err, ShouldBeNil)
327 err = os.WriteFile(excludeFile, []byte("__some_pattern"), 0755)
328 So(err, ShouldBeNil)
329
330 for _, hook := range provider.Hooks() {
331 err = hook.preExec()

Callers

nothing calls this directly

Calls 10

newMirrorProviderFunction · 0.85
TypeMethod · 0.65
NameMethod · 0.65
WorkingDirMethod · 0.65
LogDirMethod · 0.65
HooksMethod · 0.65
preExecMethod · 0.65
RunMethod · 0.65
postExecMethod · 0.65
LogFileMethod · 0.65

Tested by

no test coverage detected