Skip to content

Tests using temporary directories fail on Windows #668

@inkychris

Description

@inkychris

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions