-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_binary_test.go
More file actions
64 lines (55 loc) · 1.69 KB
/
runtime_binary_test.go
File metadata and controls
64 lines (55 loc) · 1.69 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package bbox
import (
"os"
"path/filepath"
"testing"
)
func TestRuntimeBinaryResolverPrefersPackagedBBox(t *testing.T) {
exeDir := t.TempDir()
exePath := filepath.Join(exeDir, "bbox")
if err := os.WriteFile(exePath, []byte("#!/bin/sh\n"), 0o755); err != nil {
t.Fatal(err)
}
resolver := newRuntimeBinaryResolver()
resolver.executablePath = func() (string, error) { return exePath, nil }
got, err := resolver.RuntimeBinary()
if err != nil {
t.Fatal(err)
}
if got != exePath {
t.Fatalf("got %q want %q", got, exePath)
}
}
func TestRuntimeBinaryResolverBuildsOnlyBBoxForSourceFallback(t *testing.T) {
moduleRoot := t.TempDir()
if err := os.WriteFile(filepath.Join(moduleRoot, "go.mod"), []byte("module example.com/test\n"), 0o644); err != nil {
t.Fatal(err)
}
buildDir := t.TempDir()
bboxPath := filepath.Join(buildDir, "bbox")
bboxBuilds := 0
resolver := newRuntimeBinaryResolver()
resolver.executablePath = func() (string, error) { return "", nil }
resolver.packageRoot = func() (string, error) { return moduleRoot, nil }
resolver.makeTempDir = func(_, _ string) (string, error) { return buildDir, nil }
resolver.buildBBox = func(root, out string) error {
bboxBuilds++
if root != moduleRoot {
t.Fatalf("unexpected build root: got %q want %q", root, moduleRoot)
}
if out != bboxPath {
t.Fatalf("unexpected bbox path: got %q want %q", out, bboxPath)
}
return os.WriteFile(out, []byte("#!/bin/sh\n"), 0o755)
}
got, err := resolver.RuntimeBinary()
if err != nil {
t.Fatal(err)
}
if got != bboxPath {
t.Fatalf("unexpected runtime binary path: got %q want %q", got, bboxPath)
}
if bboxBuilds != 1 {
t.Fatalf("expected one bbox build, got %d", bboxBuilds)
}
}