package flock import ( "testing" "time" ) func Test_Lock_basic(t *testing.T) { ch := make(chan int, 1) f, err := Lock("/tmp/fsutil-test-lock") if err != nil { t.Fatal(err) } go func() { time.Sleep(time.Second) ch <- 10 Unlock(f) }() select { case x := <-ch: t.Fatal(x) default: } _, _ = Lock("/tmp/fsutil-test-lock") select { case i := <-ch: if i != 10 { t.Fatal(i) } default: t.Fatal("No value available.") } } func Test_Lock_badPath(t *testing.T) { _, err := Lock("./dne/file.lock") if err == nil { t.Fatal(err) } }