provider_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package worker
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func TestRsyncProvider(t *testing.T) {
  7. Convey("Rsync Provider should work", t, func() {
  8. c := rsyncConfig{
  9. name: "tuna",
  10. upstreamURL: "rsync://rsync.tuna.moe/tuna/",
  11. workingDir: "/srv/mirror/production/tuna",
  12. logDir: "/var/log/tunasync",
  13. logFile: "tuna.log",
  14. useIPv6: true,
  15. interval: 600,
  16. }
  17. provider, err := newRsyncProvider(c)
  18. So(err, ShouldBeNil)
  19. So(provider.Name(), ShouldEqual, c.name)
  20. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  21. So(provider.LogDir(), ShouldEqual, c.logDir)
  22. So(provider.LogFile(), ShouldEqual, c.logFile)
  23. Convey("When entering a context (auto exit)", func() {
  24. func() {
  25. ctx := provider.EnterContext()
  26. defer provider.ExitContext()
  27. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  28. newWorkingDir := "/srv/mirror/working/tuna"
  29. ctx.Set(_WorkingDirKey, newWorkingDir)
  30. So(provider.WorkingDir(), ShouldEqual, newWorkingDir)
  31. }()
  32. Convey("After context is done", func() {
  33. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  34. })
  35. })
  36. Convey("When entering a context (manually exit)", func() {
  37. ctx := provider.EnterContext()
  38. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  39. newWorkingDir := "/srv/mirror/working/tuna"
  40. ctx.Set(_WorkingDirKey, newWorkingDir)
  41. So(provider.WorkingDir(), ShouldEqual, newWorkingDir)
  42. Convey("After context is done", func() {
  43. provider.ExitContext()
  44. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  45. })
  46. })
  47. })
  48. }