(t *testing.T)
| 209 | } |
| 210 | |
| 211 | func 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 |
| 244 | echo "syncing to $(pwd)" |
| 245 | echo $@ |
| 246 | sleep 1 |
| 247 | echo "Done" |
| 248 | exit 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)) |
nothing calls this directly
no test coverage detected