zfs_hook_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package worker
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestZFSHook(t *testing.T) {
  11. Convey("ZFS Hook should work", t, func(ctx C) {
  12. tmpDir, err := ioutil.TempDir("", "tunasync")
  13. tmpFile := filepath.Join(tmpDir, "log_file")
  14. c := cmdConfig{
  15. name: "tuna_zfs_hook_test",
  16. upstreamURL: "http://mirrors.tuna.moe/",
  17. command: "ls",
  18. workingDir: tmpDir,
  19. logDir: tmpDir,
  20. logFile: tmpFile,
  21. interval: 1 * time.Second,
  22. }
  23. provider, err := newCmdProvider(c)
  24. So(err, ShouldBeNil)
  25. Convey("When working directory doesn't exist", func(ctx C) {
  26. errRm := os.RemoveAll(tmpDir)
  27. So(errRm, ShouldBeNil)
  28. hook := newZfsHook(provider, "test_pool")
  29. err := hook.preJob()
  30. So(err, ShouldNotBeNil)
  31. })
  32. Convey("When working directory is not a mount point", func(ctx C) {
  33. defer os.RemoveAll(tmpDir)
  34. hook := newZfsHook(provider, "test_pool")
  35. err := hook.preJob()
  36. So(err, ShouldNotBeNil)
  37. })
  38. })
  39. }