(t *testing.T)
| 272 | } |
| 273 | |
| 274 | func 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 "$@" |
| 317 | while [[ $# -gt 0 ]]; do |
| 318 | if [[ "$1" = "--exclude-from" ]]; then |
| 319 | cat "$2" |
| 320 | shift |
| 321 | fi |
| 322 | shift |
| 323 | done |
| 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() |
nothing calls this directly
no test coverage detected