internal/toolpath/toolpath_test.go

28e72be7ab6bc96868893853fd8d210c3656960f
gitbay/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}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form