forked from mattn/gom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_test.go
68 lines (64 loc) · 1.23 KB
/
gen_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
63
64
65
66
67
68
package main
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)
func TestGomfile(t *testing.T) {
dir, err := ioutil.TempDir("", "gom")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
// 'go env GOPATH' returns followed links while ioutil.TempDir(os.TempDir) may returns symbolic link
dir, err = filepath.EvalSymlinks(dir)
if err != nil {
t.Fatal(err)
}
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, vendorFolder)
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", "GOPATH"}, None)
if err != nil {
t.Fatal(err)
}
f.Close()
stdout = oldstdout
b, err := ioutil.ReadFile(f.Name())
if err != nil {
t.Fatal(err)
}
gopath := string(b)
found := false
for _, s := range strings.Split(gopath, string(filepath.ListSeparator)) {
if filepath.Clean(s) == filepath.Clean(vendor) {
found = true
break
}
}
if !found {
t.Fatalf("Expected %v, but %v:", vendor, found)
}
}