mirror of
https://github.com/golang/go.git
synced 2026-06-28 03:40:37 +00:00
encoding/json/internal/jsontest: rename testdata to _embed
Various tools assume that testdata directories are unnecessary if you don't need to run tests. This includes cmd/internal/bootstrap_test, which runs go install std on a GOROOT excluding testdata directories. Since this is an importable package rather than a test, to avoid breaking that case we must not actually name the directory testdata. We may want to reevaluate whether we want a dedicated package with embedded testdata at all, but for now the simple fix for the currently broken longtest builders is to simply rename the directory. For #71497. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Change-Id: Ic14ce7b06dca36cc758f99374da378c46a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/779302 Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com> TryBot-Bypass: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
722ee60825
commit
c7a107bfbf
8 changed files with 9 additions and 3 deletions
|
|
@ -25,7 +25,13 @@ import (
|
|||
// by other packages such that the location of testdata may change relative
|
||||
// to the working directory of the test itself.
|
||||
//
|
||||
//go:embed testdata/*.json.zst
|
||||
// Various tools assume that testdata directories are unnecessary if you don't
|
||||
// need to run tests. This includes cmd/internal/bootstrap_test, which runs go
|
||||
// install std on a GOROOT excluding testdata directories. Since this is an
|
||||
// importable package rather than a test, to avoid breaking that case we must
|
||||
// not actually name the directory testdata.
|
||||
//
|
||||
//go:embed _embed/*.json.zst
|
||||
var testdataFS embed.FS
|
||||
|
||||
type Entry struct {
|
||||
|
|
@ -43,7 +49,7 @@ func mustGet[T any](v T, err error) T {
|
|||
|
||||
// Data is a list of JSON testdata.
|
||||
var Data = func() (entries []Entry) {
|
||||
fis := mustGet(fs.ReadDir(testdataFS, "testdata"))
|
||||
fis := mustGet(fs.ReadDir(testdataFS, "_embed"))
|
||||
slices.SortFunc(fis, func(x, y fs.DirEntry) int { return strings.Compare(x.Name(), y.Name()) })
|
||||
for _, fi := range fis {
|
||||
var entry Entry
|
||||
|
|
@ -57,7 +63,7 @@ var Data = func() (entries []Entry) {
|
|||
|
||||
// Lazily read and decompress the test data.
|
||||
entry.Data = sync.OnceValue(func() []byte {
|
||||
filePath := path.Join("testdata", fi.Name())
|
||||
filePath := path.Join("_embed", fi.Name())
|
||||
b := mustGet(fs.ReadFile(testdataFS, filePath))
|
||||
zr := zstd.NewReader(bytes.NewReader(b))
|
||||
return mustGet(io.ReadAll(zr))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue