From 90d419ca66bdd0afd749e441225609f4e1bac9ca Mon Sep 17 00:00:00 2001 From: zyx Date: Sun, 31 Mar 2019 12:16:45 +0800 Subject: [PATCH] add tests for last commit --- worker/zfs_hook_test.go | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 worker/zfs_hook_test.go diff --git a/worker/zfs_hook_test.go b/worker/zfs_hook_test.go new file mode 100644 index 0000000..cf24a59 --- /dev/null +++ b/worker/zfs_hook_test.go @@ -0,0 +1,48 @@ +package worker + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + "time" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestZFSHook(t *testing.T) { + + Convey("ZFS Hook should work", t, func(ctx C) { + tmpDir, err := ioutil.TempDir("", "tunasync") + tmpFile := filepath.Join(tmpDir, "log_file") + + c := cmdConfig{ + name: "tuna_zfs_hook_test", + upstreamURL: "http://mirrors.tuna.moe/", + command: "ls", + workingDir: tmpDir, + logDir: tmpDir, + logFile: tmpFile, + interval: 1 * time.Second, + } + + provider, err := newCmdProvider(c) + So(err, ShouldBeNil) + Convey("When working directory doesn't exist", func(ctx C) { + + errRm := os.RemoveAll(tmpDir) + So(errRm, ShouldBeNil) + + hook := newZfsHook(provider, "test_pool") + err := hook.preJob() + So(err, ShouldNotBeNil) + }) + Convey("When working directory is not a mount point", func(ctx C) { + defer os.RemoveAll(tmpDir) + + hook := newZfsHook(provider, "test_pool") + err := hook.preJob() + So(err, ShouldNotBeNil) + }) + }) +} \ No newline at end of file