@@ -42,8 +42,7 @@ type TestResult struct {
42
42
}
43
43
44
44
func getProjectRoot () string {
45
- gopath := os .Getenv ("GOPATH" )
46
- return path .Join (gopath , "src" , "sigs.k8s.io" , "kubebuilder" )
45
+ return path .Join (build .Default .GOPATH , "src" , "sigs.k8s.io" , "kubebuilder" )
47
46
}
48
47
49
48
// ProjectPath is the path to the controller-tools/testdata project file
@@ -66,6 +65,7 @@ func Options() input.Options {
66
65
67
66
// NewTestScaffold returns a new Scaffold and TestResult instance for testing
68
67
func NewTestScaffold (writeToPath , goldenPath string ) (* scaffold.Scaffold , * TestResult ) {
68
+ projRoot := getProjectRoot ()
69
69
r := & TestResult {}
70
70
// Setup scaffold
71
71
s := & scaffold.Scaffold {
@@ -74,12 +74,20 @@ func NewTestScaffold(writeToPath, goldenPath string) (*scaffold.Scaffold, *TestR
74
74
gomega .Expect (path ).To (gomega .Equal (writeToPath ))
75
75
return & r .Actual , nil
76
76
},
77
- ProjectPath : filepath .Join (getProjectRoot (), "testdata" , "gopath" , "src" , "project" ),
77
+ FileExists : func (path string ) bool {
78
+ return path != writeToPath
79
+ },
80
+ ProjectPath : filepath .Join (projRoot , "testdata" , "gopath" , "src" , "project" ),
81
+ }
82
+ oldGoPath := build .Default .GOPATH
83
+ build .Default .GOPATH = filepath .Join (projRoot , "testdata" , "gopath" )
84
+ defer func () { build .Default .GOPATH = oldGoPath }()
85
+ if _ , err := os .Stat (build .Default .GOPATH ); err != nil {
86
+ panic (err )
78
87
}
79
- build .Default .GOPATH = filepath .Join (getProjectRoot (), "testdata" , "gopath" )
80
88
81
89
if len (goldenPath ) > 0 {
82
- b , err := ioutil .ReadFile (filepath .Join (getProjectRoot () , "testdata" , "gopath" , "src" , "project" , goldenPath ))
90
+ b , err := ioutil .ReadFile (filepath .Join (projRoot , "testdata" , "gopath" , "src" , "project" , goldenPath ))
83
91
gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
84
92
r .Golden = string (b )
85
93
}
0 commit comments