-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_test.go
51 lines (45 loc) · 1.12 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
package main
import (
"os"
"testing"
)
func TestGetGoPath(t *testing.T) {
tmpdir := os.TempDir()
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Error getting working directory: %s", err.Error())
}
origGopath := os.Getenv("GOPATH")
// Verify that getGoPath works
_, err = getGoPath(wd)
if err != nil {
t.Errorf("Expected getGoPath success, got %s", err.Error())
}
// Unset GOPATH and verify that getGoPath fails
err = os.Unsetenv("GOPATH")
if err != nil {
t.Fatal(err.Error())
}
_, err = getGoPath(wd)
if err == nil {
t.Errorf("Expected getGoPath failure, got %s", err)
}
// Set gopath to tmp directory and verify that getGoPath fails
err = os.Setenv("GOPATH", tmpdir)
if err != nil {
t.Fatal(err.Error())
}
_, err = getGoPath(wd)
if err == nil {
t.Errorf("Expected getGoPath failure, got %s", err)
}
// Set gopath to GOPATH + tmp directory and verify that getGoPath succeeds
err = os.Setenv("GOPATH", origGopath+string(os.PathListSeparator)+tmpdir)
if err != nil {
t.Fatal(err.Error())
}
_, err = getGoPath(wd)
if err != nil {
t.Errorf("Expected getGoPath failure, got %s", err.Error())
}
}