1
0
Fork 0
mirror of https://github.com/vbatts/dedupe-linker.git synced 2024-12-27 17:16:32 +00:00
dedupe-linker/base/findbase_test.go
Vincent Batts aa4b5f4c39 findbase: walk up tree to find a suitable base dir
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-09-13 10:03:42 -04:00

75 lines
1.4 KiB
Go

package base
import (
"io/ioutil"
"os"
"testing"
)
func TestHasPermission(t *testing.T) {
if !hasPermission("/tmp") {
t.Error("expected to have permission to /tmp, but did not")
}
if hasPermission("/") {
t.Error("expected to not have permission to /, but did")
}
}
func TestSameDev(t *testing.T) {
file1, err := ioutil.TempFile("", "test")
if err != nil {
t.Fatal(err)
}
defer file1.Close()
file2, err := ioutil.TempFile("", "test")
if err != nil {
t.Fatal(err)
}
defer file2.Close()
stat1, err := file1.Stat()
if err != nil {
t.Fatal(err)
}
stat2, err := file2.Stat()
if err != nil {
t.Fatal(err)
}
if !sameDevice(stat1, stat2) {
t.Errorf("expected the two files to be on same device. But %q and %q are not", file1.Name(), file2.Name())
} else {
os.Remove(stat1.Name())
os.Remove(stat2.Name())
}
}
func TestNotSameDev(t *testing.T) {
file1, err := ioutil.TempFile("/tmp", "test")
if err != nil {
t.Fatal(err)
}
defer file1.Close()
file2, err := ioutil.TempFile("/home/vbatts", "test")
if err != nil {
t.Fatal(err)
}
defer file2.Close()
stat1, err := file1.Stat()
if err != nil {
t.Fatal(err)
}
stat2, err := file2.Stat()
if err != nil {
t.Fatal(err)
}
if sameDevice(stat1, stat2) {
t.Errorf("expected the two files _not_ to be on same device. But %q and %q are not", file1.Name(), file2.Name())
} else {
os.Remove(stat1.Name())
os.Remove(stat2.Name())
}
}