-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexec_test.go
60 lines (58 loc) · 1.06 KB
/
exec_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
package main
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)
func TestExec(t *testing.T) {
dir, err := ioutil.TempDir("", "gom")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
err = os.Chdir(dir)
if err != nil {
t.Fatal(err)
}
defer os.Chdir(cwd)
f, err := ioutil.TempFile(dir, "gom")
if err != nil {
t.Fatal(err)
}
vendor := filepath.Join(dir, "vendor")
err = os.MkdirAll(filepath.Join(vendor, "src"), 0755)
if err != nil {
t.Fatal(err)
}
oldstdout := stdout
defer func() {
stdout = oldstdout
}()
stdout = f
err = run([]string{"go", "env"}, None)
if err != nil {
t.Fatal(err)
}
f.Close()
stdout = oldstdout
b, err := ioutil.ReadFile(f.Name())
if err != nil {
t.Fatal(err)
}
found := ""
for _, line := range strings.Split(string(b), "\n") {
item := strings.SplitN(line, " ", 2)
if len(item) > 1 && strings.HasPrefix(item[1], "GOPATH=") {
found = item[1][7:]
}
}
if found != vendor {
t.Fatalf("Expected %v, but %v:", vendor, found)
}
}