1
0
Fork 0
mirror of https://github.com/vbatts/dedupe-linker.git synced 2024-11-16 05:38:38 +00:00
dedupe-linker/base/findbase_test.go

76 lines
1.4 KiB
Go
Raw Normal View History

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())
}
}