-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
62 lines (48 loc) · 1.11 KB
/
main_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
51
52
53
54
55
56
57
58
59
60
61
62
package main_test
import (
"flag"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
var (
cli = flag.String("cli", "", "The CLI binary")
version = "dev"
)
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
// Make sure that the x_defs override is working with the bazel build.
func TestDefaultVersion(t *testing.T) {
t.Parallel()
if version != "dev" {
t.Error("Expected", "dev", "got", version)
}
}
func TestCLIVersion(t *testing.T) {
t.Parallel()
path, err := bazel.Runfile(*cli)
if err != nil {
t.Fatalf("Could not find runfile %s: %q", *cli, err)
}
if _, err = os.Stat(path); os.IsNotExist(err) {
t.Fatalf("Missing binary %v", path)
}
file, err := filepath.EvalSymlinks(path)
if err != nil {
t.Fatalf("Invalid filename %v", path)
}
cmd := exec.Command(file, "--version")
cmd.Stderr = os.Stderr
res, err := cmd.Output()
if err != nil {
t.Fatalf("failed running '%v': %v", path, err)
}
output := strings.TrimSpace(string(res))
if output != "dev.bazel version" {
t.Error("Expected", "dev.bazel version", "got", output)
}
}