-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_test.go
47 lines (44 loc) · 1.56 KB
/
path_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
package main
import (
"os"
"path/filepath"
"testing"
)
// TestPath test the path subcommand to make sure that it properly changes
// imports, including imports of child packages.
// Also this command tests the call without recursion into subdirectories,
// checks to make sure they are not affected.
func TestUpdate(t *testing.T) {
ctx := getTestContextCopy(t, filepath.Join("testdata", "update"))
defer os.RemoveAll(ctx.GOPATH)
pkgDir := filepath.Join(ctx.GOPATH, "src", "example.com", "x")
err := path(ctx, pkgDir, "go", "mygo", false)
if err != nil {
t.Errorf("update error : %s", err.Error())
}
testImports(t, pkgDir,
[]string{"fmt", "os", "mygo/ast", "mygo/build", "mygo/parser"},
false)
// Test that child package was not updated.
childPkgDir := filepath.Join(pkgDir, "y")
testImports(t, childPkgDir,
[]string{"fmt", "os", "go/ast", "go/parser"}, false)
}
// TestPathRecurse test the path subcommand with the recurse option. Makes sure
// subdirectory package is also updated.
func TestPathRecurse(t *testing.T) {
ctx := getTestContextCopy(t, filepath.Join("testdata", "update"))
defer os.RemoveAll(ctx.GOPATH)
pkgDir := filepath.Join(ctx.GOPATH, "src", "example.com", "x")
err := path(ctx, pkgDir, "go", "mygo", true)
if err != nil {
t.Errorf("update error : %s", err.Error())
}
testImports(t, pkgDir,
[]string{"fmt", "os", "mygo/ast", "mygo/build", "mygo/parser"},
false)
// Test child package was updated as well.
childPkgDir := filepath.Join(pkgDir, "y")
testImports(t, childPkgDir,
[]string{"fmt", "os", "mygo/ast", "mygo/parser"}, false)
}