provider_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. So(provider.Interval(), ShouldEqual, c.interval)
  24. Convey("When entering a context (auto exit)", func() {
  25. func() {
  26. ctx := provider.EnterContext()
  27. defer provider.ExitContext()
  28. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  29. newWorkingDir := "/srv/mirror/working/tuna"
  30. ctx.Set(_WorkingDirKey, newWorkingDir)
  31. So(provider.WorkingDir(), ShouldEqual, newWorkingDir)
  32. }()
  33. Convey("After context is done", func() {
  34. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  35. })
  36. })
  37. Convey("When entering a context (manually exit)", func() {
  38. ctx := provider.EnterContext()
  39. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  40. newWorkingDir := "/srv/mirror/working/tuna"
  41. ctx.Set(_WorkingDirKey, newWorkingDir)
  42. So(provider.WorkingDir(), ShouldEqual, newWorkingDir)
  43. Convey("After context is done", func() {
  44. provider.ExitContext()
  45. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  46. })
  47. })
  48. })
  49. }