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

Function TestRsyncProviderWithOverriddenOptions

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

Source from the content-addressed store, hash-verified

209}
210
211func TestRsyncProviderWithOverriddenOptions(t *testing.T) {
212 Convey("Rsync Provider with overridden options should work", t, func() {
213 tmpDir, err := os.MkdirTemp("", "tunasync")
214 defer os.RemoveAll(tmpDir)
215 So(err, ShouldBeNil)
216 scriptFile := filepath.Join(tmpDir, "myrsync")
217 tmpFile := filepath.Join(tmpDir, "log_file")
218
219 c := rsyncConfig{
220 name: "tuna",
221 upstreamURL: "rsync://rsync.tuna.moe/tuna/",
222 rsyncCmd: scriptFile,
223 workingDir: tmpDir,
224 rsyncNeverTimeout: true,
225 overriddenOptions: []string{"-aHvh", "--no-o", "--no-g", "--stats"},
226 extraOptions: []string{"--delete-excluded"},
227 logDir: tmpDir,
228 logFile: tmpFile,
229 useIPv6: true,
230 interval: 600 * time.Second,
231 }
232
233 provider, err := newRsyncProvider(c)
234 So(err, ShouldBeNil)
235
236 So(provider.Name(), ShouldEqual, c.name)
237 So(provider.WorkingDir(), ShouldEqual, c.workingDir)
238 So(provider.LogDir(), ShouldEqual, c.logDir)
239 So(provider.LogFile(), ShouldEqual, c.logFile)
240 So(provider.Interval(), ShouldEqual, c.interval)
241
242 Convey("Let's try a run", func() {
243 scriptContent := `#!/bin/bash
244echo "syncing to $(pwd)"
245echo $@
246sleep 1
247echo "Done"
248exit 0
249 `
250 err = os.WriteFile(scriptFile, []byte(scriptContent), 0755)
251 So(err, ShouldBeNil)
252
253 targetDir, _ := filepath.EvalSymlinks(provider.WorkingDir())
254 expectedOutput := fmt.Sprintf(
255 "syncing to %s\n"+
256 "-aHvh --no-o --no-g --stats -6 --delete-excluded %s %s\n"+
257 "Done\n",
258 targetDir,
259 provider.upstreamURL,
260 provider.WorkingDir(),
261 )
262
263 err = provider.Run(make(chan empty, 1))
264 So(err, ShouldBeNil)
265 loggedContent, err := os.ReadFile(provider.LogFile())
266 So(err, ShouldBeNil)
267 So(string(loggedContent), ShouldEqual, expectedOutput)
268 // fmt.Println(string(loggedContent))

Callers

nothing calls this directly

Calls 7

newRsyncProviderFunction · 0.85
NameMethod · 0.65
WorkingDirMethod · 0.65
LogDirMethod · 0.65
LogFileMethod · 0.65
IntervalMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected