internal/toolpath/toolpath_test.go
47 lines · 1238 bytes
1package toolpath
2
3import (
4 "os/exec"
5 "path/filepath"
6 "strings"
7 "testing"
8)
9
10func TestLookResolvesToAnAbsolutePath(t *testing.T) {
11 got := Look("go")
12 if !filepath.IsAbs(got) {
13 t.Fatalf("Look(go) = %q, want an absolute path", got)
14 }
15 want, err := exec.LookPath("go")
16 if err != nil {
17 t.Fatal(err)
18 }
19 if got != want {
20 t.Errorf("Look(go) = %q, want %q", got, want)
21 }
22}
23
24// A second call must not search again: resolving once is the point, and a
25// daemon that re-resolved would follow a PATH that changed under it.
26func TestLookIsResolvedOnce(t *testing.T) {
27 first := Look("go")
28 if second := Look("go"); second != first {
29 t.Errorf("Look(go) returned %q then %q", first, second)
30 }
31}
32
33// An absent tool falls back to the bare name so exec reports it the way
34// it always did, and Verify names it.
35func TestMissingToolFallsBackAndIsReported(t *testing.T) {
36 const name = "gitbay-no-such-tool-exists"
37 if got := Look(name); got != name {
38 t.Errorf("Look(%q) = %q, want the bare name back", name, got)
39 }
40 err := Verify()
41 if err == nil {
42 t.Fatal("Verify found nothing missing after an unresolvable lookup")
43 }
44 if !strings.Contains(err.Error(), name) {
45 t.Errorf("Verify error %q does not name the missing tool", err)
46 }
47}