go-playground/universal-translator

go test all fails for all dependent projects

frncmx opened this issue · 0 comments

What did you do?

I run go test all for my project which has universal-translator as an indirect dependency and it uses go modules.

What did you expect to see?

All tests passed.

What did you see instead?

> go test all
[...]
ok      github.com/go-playground/locales/nl     (cached)
testdata/translations stat testdata/translations: no such file or directory true
--- FAIL: TestExportImportBasic (0.00s)
    import_export_test.go:106: Expected '<nil>' Got 'mkdir testdata/translations: permission denied'
testdata/translations stat testdata/translations: no such file or directory true
--- FAIL: TestExportImportCardinal (0.00s)
    import_export_test.go:235: Expected '<nil>' Got 'mkdir testdata/translations: permission denied'
testdata/translations stat testdata/translations: no such file or directory true
--- FAIL: TestExportImportOrdinal (0.00s)
    import_export_test.go:372: Expected '<nil>' Got 'mkdir testdata/translations: permission denied'
testdata/translations stat testdata/translations: no such file or directory true
--- FAIL: TestExportImportRange (0.00s)
    import_export_test.go:535: Expected '<nil>' Got 'mkdir testdata/translations: permission denied'
--- FAIL: TestBadExport (0.00s)
    import_export_test.go:771: Expected '<nil>' Got 'mkdir testdata/readonly: permission denied'
FAIL
FAIL    github.com/go-playground/universal-translator   0.042s
ok      go/ast  (cached)
[...]
FAIL

How to reproduce?

The slow but exact way: run docker build . with the following Dockerfile:

FROM golang:1.14
WORKDIR /go/src

RUN printf '\
package main \n\
import "github.com/go-playground/universal-translator" \n\
var _ *ut.UniversalTranslator \n\
func main() {} \n\
' > main.go

RUN go mod init example.com/m \
    && go mod tidy

RUN go test all

The fast and hacky way:

cd $GOPATH/src/github.com/go-playground/universal-translator
ls -ld ./testdata/ # so that you remember the mods
chmod 555 ./testdata/
go test ./...

What is the root cause?

  1. The failing tests create temporary directories in the projects testdata dir.
  2. When running go test all the Go tool changes directory to $GOPATH/pkg/mod/pkg/mod/github.com/go-playground/universal-translator@v0.17.0 to run the tests.
  3. Directories under $GOPATH/pkg/mod/pkg/mod/` are readonly.
    => The tests fail.