zfs_hook_test.go 1020 B

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