Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests using temporary directories fail on Windows #668

Closed
inkychris opened this issue Mar 15, 2019 · 2 comments
Closed

Tests using temporary directories fail on Windows #668

inkychris opened this issue Mar 15, 2019 · 2 comments

Comments

@inkychris
Copy link
Contributor

Running go test on Windows results in the following failure:

--- FAIL: TestDirsSearch (0.00s)
    viper_test.go:208:
                Error Trace:    viper_test.go:208
                                                        viper_test.go:854
                Error:          Expected nil, but got: &os.PathError{Op:"mkdir", Path:"C:\\Windows\\959449095", Err:0x5}
                Test:           TestDirsSearch
    viper_test.go:211:
                Error Trace:    viper_test.go:211
                                                        viper_test.go:854
                Error:          Expected nil, but got: &os.PathError{Op:"chdir", Path:"", Err:0x7b}
                Test:           TestDirsSearch
    viper_test.go:215:
                Error Trace:    viper_test.go:215
                                                        viper_test.go:854
                Error:          Expected nil, but got: &os.PathError{Op:"mkdir", Path:"a a", Err:0xb7}
                Test:           TestDirsSearch
    viper_test.go:215:
                Error Trace:    viper_test.go:215
                                                        viper_test.go:854
                Error:          Expected nil, but got: &os.PathError{Op:"mkdir", Path:"b", Err:0xb7}
                Test:           TestDirsSearch
    viper_test.go:215:
                Error Trace:    viper_test.go:215
                                                        viper_test.go:854
                Error:          Expected nil, but got: &os.PathError{Op:"mkdir", Path:"c\\c", Err:0x3}
                Test:           TestDirsSearch
    viper_test.go:221:
                Error Trace:    viper_test.go:221
                                                        viper_test.go:854
                Error:          Expected nil, but got: &os.PathError{Op:"open", Path:"c\\c/improbable.toml", Err:0x3}
                Test:           TestDirsSearch
    viper_test.go:215:
                Error Trace:    viper_test.go:215
                                                        viper_test.go:854
                Error:          Expected nil, but got: &os.PathError{Op:"mkdir", Path:"D_", Err:0xb7}
                Test:           TestDirsSearch
    viper_test.go:869:
                Error Trace:    viper_test.go:869
                Error:          Expected nil, but got: viper.ConfigFileNotFoundError{name:"improbable", locations:"[]"}
                Test:           TestDirsSearch
panic: runtime error: index out of range [recovered]
        panic: runtime error: index out of range

goroutine 49 [running]:
testing.tRunner.func1(0xc00021aa00)
        C:/Go/src/testing/testing.go:830 +0x38f
panic(0x8c3a60, 0xd1db70)
        C:/Go/src/runtime/panic.go:522 +0x1c3
github.com/spf13/viper.TestDirsSearch(0xc00021aa00)
        C:/Users/chris/go/src/github.com/spf13/viper/viper_test.go:871 +0x4b6
testing.tRunner(0xc00021aa00, 0x9593e8)
        C:/Go/src/testing/testing.go:865 +0xc7
created by testing.(*T).Run
        C:/Go/src/testing/testing.go:916 +0x35e
exit status 2
FAIL    github.com/spf13/viper  0.236s

Given the path returned by the first error trace, I imagine that one is due to file permissions trying to write to C:\Windows. This would imply that perhaps the test isn't running where it thinks it is? Running the same test in isolation with GoLand returns the following which I think supports this:

GOROOT=C:\Go #gosetup
GOPATH=C:\Users\chris\go #gosetup
C:\Go\bin\go.exe test -c -o C:\Users\chris\AppData\Local\Temp\___TestDirsSearch_in_github_com_spf13_viper.exe github.com/spf13/viper #gosetup
"C:\Program Files\JetBrains\GoLand 2018.3.5\bin\runnerw64.exe" C:\Go\bin\go.exe tool test2json -t C:\Users\chris\AppData\Local\Temp\___TestDirsSearch_in_github_com_spf13_viper.exe -test.v -test.run ^TestDirsSearch$ #gosetup
=== RUN   TestDirsSearch
--- FAIL: TestDirsSearch (0.01s)
    viper_test.go:215: 
        	Error Trace:	viper_test.go:215
        	            				viper_test.go:854
        	Error:      	Expected nil, but got: &os.PathError{Op:"mkdir", Path:"c\\c", Err:0x3}
        	Test:       	TestDirsSearch
    viper_test.go:221: 
        	Error Trace:	viper_test.go:221
        	            				viper_test.go:854
        	Error:      	Expected nil, but got: &os.PathError{Op:"open", Path:"c\\c/improbable.toml", Err:0x3}
        	Test:       	TestDirsSearch
    viper_test.go:871: 
        	Error Trace:	viper_test.go:871
        	Error:      	Not equal: 
        	            	expected: "value is C:\\Users\\chris\\AppData\\Local\\Temp\\366897299\\D_"
        	            	actual  : "value is D_"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-value is C:\Users\chris\AppData\Local\Temp\366897299\D_
        	            	+value is D_
        	Test:       	TestDirsSearch


Expected :value is C:\Users\chris\AppData\Local\Temp\366897299\D_
Actual   :value is D_
 <Click to see difference>


FAIL

Process finished with exit code 1
@inkychris
Copy link
Contributor Author

To update, this appears to be an issue with all tests that assume behaviour of temporary files and directories. Other tests that fail:

  • TestWatchFile/file_content_changed
  • TestWrongDirsSearchNotFound
  • TestWrongDirsSearchNotFoundForMerge

@inkychris inkychris changed the title TestDirsSearch fails on Windows Tests using temporary directories fails on Windows Mar 16, 2019
@inkychris inkychris changed the title Tests using temporary directories fails on Windows Tests using temporary directories fail on Windows Mar 16, 2019
@inkychris
Copy link
Contributor Author

Fixed by #673

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants