-
Notifications
You must be signed in to change notification settings - Fork 49
/
sigil_test.go
50 lines (46 loc) · 1.03 KB
/
sigil_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package sigil
import (
"os"
"path/filepath"
"testing"
)
func TestLookPath(t *testing.T) {
for _, tmpDir := range []string{"", "."} {
for _, relative := range []bool{true, false} {
for _, exists := range []bool{true, false} {
// setup
f, err := os.CreateTemp(tmpDir, "sigiltest")
if err != nil {
t.Error("failed to crate temporary file")
continue
}
relpath := f.Name()
fullpath, err := filepath.Abs(f.Name())
if err != nil {
t.Error("failed to get the absolute path")
}
if !exists {
os.Remove(f.Name())
}
path := fullpath
if relative {
path = relpath
}
// test
p, err := LookPath(path)
if exists {
if p != fullpath {
t.Errorf("expected %s but %s; tmpDir=%s, relative=%v, exists=%v", fullpath, p, tmpDir, relative, exists)
}
} else {
if err == nil {
t.Errorf("expected error. tmpDir=%s, relative=%v, exists=%v", tmpDir, relative, exists)
}
}
// teardown
f.Close()
os.Remove(f.Name())
}
}
}
}