Skip to content

Commit

Permalink
pkg/testutils: Add check for golden file name creator
Browse files Browse the repository at this point in the history
This commit is required to make future additions of
the golden files compatible with the Go module restrictions
on file names.

Every existing file returned by a pattern `*.golden.*` has
been checked against the `module.CheckFilePath()` to ensure
that all existing ones are compliant with the Go module
restrictions.

This commit adds a dependency on the golang.org/x/mod package.

See:
- https://go.dev/ref/mod#zip-path-size-constraints
  • Loading branch information
mrVanboy authored and mmatczuk committed Jul 13, 2022
1 parent 7e41f31 commit 953caa3
Show file tree
Hide file tree
Showing 135 changed files with 1,282 additions and 8,974 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ require (
go.uber.org/multierr v1.6.0
go.uber.org/zap v1.21.0
golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9
golang.org/x/mod v0.4.2
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210510120138-977fb7262007
golang.org/x/tools v0.1.5
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
18 changes: 14 additions & 4 deletions pkg/testutils/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"path"
"strings"
"testing"

"golang.org/x/mod/module"
)

var flagUpdate = flag.Bool("update", false, "update .golden files")
Expand Down Expand Up @@ -40,10 +42,14 @@ func SaveGoldenJSONFileIfNeeded(tb testing.TB, v interface{}) {
tb.Fatal(err)
}

if err := os.MkdirAll(path.Dir(goldenJSONFileName(tb)), 0o777); err != nil {
filename := goldenJSONFileName(tb)
if err := module.CheckFilePath(filename); err != nil {
tb.Fatalf("cannot use name of the test to store golden file %q: %v", filename, err)
}
if err := os.MkdirAll(path.Dir(filename), 0o777); err != nil {
tb.Fatal(err)
}
if err := os.WriteFile(goldenJSONFileName(tb), buf.Bytes(), 0o666); err != nil {
if err := os.WriteFile(filename, buf.Bytes(), 0o666); err != nil {
tb.Error(err)
}
}
Expand Down Expand Up @@ -76,10 +82,14 @@ func SaveGoldenTextFileIfNeeded(tb testing.TB, s string) {
return
}

if err := os.MkdirAll(path.Dir(goldenTextFileName(tb)), 0o777); err != nil {
filename := goldenTextFileName(tb)
if err := module.CheckFilePath(filename); err != nil {
tb.Fatalf("cannot use name of the test to store golden file %q: %v", filename, err)
}
if err := os.MkdirAll(path.Dir(filename), 0o777); err != nil {
tb.Fatal(err)
}
if err := os.WriteFile(goldenTextFileName(tb), []byte(s), 0o666); err != nil {
if err := os.WriteFile(filename, []byte(s), 0o666); err != nil {
tb.Error(err)
}
}
Expand Down
1 change: 0 additions & 1 deletion vendor/github.com/golang/mock/.github/CODEOWNERS

This file was deleted.

28 changes: 0 additions & 28 deletions vendor/github.com/golang/mock/.github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

This file was deleted.

This file was deleted.

55 changes: 0 additions & 55 deletions vendor/github.com/golang/mock/.github/workflows/test.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions vendor/github.com/golang/mock/.gitignore

This file was deleted.

42 changes: 0 additions & 42 deletions vendor/github.com/golang/mock/.goreleaser.yml

This file was deleted.

19 changes: 0 additions & 19 deletions vendor/github.com/golang/mock/CONTRIBUTING.md

This file was deleted.

Loading

0 comments on commit 953caa3

Please sign in to comment.