From 3bec306587c6dae22f837aa33521cf2143ca4d69 Mon Sep 17 00:00:00 2001 From: Kioni Date: Fri, 31 May 2024 01:16:25 +0900 Subject: [PATCH] cmd/go: add test script for list -m -json Add test script to check 'go list -m -json' include an Origin. --- src/cmd/go/internal/modload/query_test.go | 6 ++ .../testdata/script/mod_list_issue61423.txt | 2 +- .../testdata/script/mod_list_issue67363.txt | 87 +++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/cmd/go/testdata/script/mod_list_issue67363.txt diff --git a/src/cmd/go/internal/modload/query_test.go b/src/cmd/go/internal/modload/query_test.go index 93f8f0d00d1..f5c85ce52bd 100644 --- a/src/cmd/go/internal/modload/query_test.go +++ b/src/cmd/go/internal/modload/query_test.go @@ -197,6 +197,12 @@ func TestQuery(t *testing.T) { if info.Version != tt.vers { t.Errorf("Query(_, %q, %q, %q, %v) = %v, want %v", tt.path, tt.query, tt.current, allow, info.Version, tt.vers) } + + if strings.HasPrefix(tt.query, "v") || tt.query == "latest" { + if info.Origin == nil { + t.Errorf("Query(_, %q, %q, %q, %v) = %v, info.Origin is nil", tt.path, tt.query, tt.current, allow, info.Version) + } + } }) } } diff --git a/src/cmd/go/testdata/script/mod_list_issue61423.txt b/src/cmd/go/testdata/script/mod_list_issue61423.txt index 2888391f6d6..827fb2f24ae 100644 --- a/src/cmd/go/testdata/script/mod_list_issue61423.txt +++ b/src/cmd/go/testdata/script/mod_list_issue61423.txt @@ -57,7 +57,7 @@ env GOMODCACHE=$WORK/modcache2 go list -m -json vcs-test.golang.org/git/issue61415.git@latest cp stdout proxy-latest.json stdout '"Version": "v0.0.0-20231114180000-08a4fa6bb9c0"' -! stdout '"Origin":' +stdout '"Origin":' # However, if we list a specific, stable version, we should get # whatever origin metadata the proxy has for the version. diff --git a/src/cmd/go/testdata/script/mod_list_issue67363.txt b/src/cmd/go/testdata/script/mod_list_issue67363.txt new file mode 100644 index 00000000000..d8f47a9f48a --- /dev/null +++ b/src/cmd/go/testdata/script/mod_list_issue67363.txt @@ -0,0 +1,87 @@ +# Test for #67363: fixes let 'go list -m -json' include an Origin + +env GOPROXY=https://proxy.golang.org + +go list -m -json golang.org/x/arch@latest +stdout 'Origin' + +go list -m -json golang.org/x/benchmarks@latest +stdout 'Origin' + +go list -m -json golang.org/x/build@latest +stdout 'Origin' + +go list -m -json golang.org/x/crypto@latest +stdout 'Origin' + +go list -m -json golang.org/x/debug@latest +stdout 'Origin' + +go list -m -json golang.org/x/example@latest +stdout 'Origin' + +go list -m -json golang.org/x/exp@latest +stdout 'Origin' + +go list -m -json golang.org/x/image@latest +stdout 'Origin' + +go list -m -json golang.org/x/mobile@latest +stdout 'Origin' + +go list -m -json golang.org/x/mod@latest +stdout 'Origin' + +go list -m -json golang.org/x/net@latest +stdout 'Origin' + +go list -m -json golang.org/x/oauth2@latest +stdout 'Origin' + +go list -m -json golang.org/x/perf@latest +stdout 'Origin' + +go list -m -json golang.org/x/pkgsite@latest +stdout 'Origin' + +go list -m -json golang.org/x/pkgsite-metrics@latest +stdout 'Origin' + +go list -m -json golang.org/x/playground@latest +stdout 'Origin' + +go list -m -json golang.org/x/review@latest +stdout 'Origin' + +go list -m -json golang.org/x/sync@latest +stdout 'Origin' + +go list -m -json golang.org/x/sys@latest +stdout 'Origin' + +go list -m -json golang.org/x/term@latest +stdout 'Origin' + +go list -m -json golang.org/x/text@latest +stdout 'Origin' + +go list -m -json golang.org/x/time@latest +stdout 'Origin' + +go list -m -json golang.org/x/tools@latest +stdout 'Origin' + +go list -m -json golang.org/x/vgo@latest +stdout 'Origin' + +go list -m -json golang.org/x/vuln@latest +stdout 'Origin' + +go list -m -json golang.org/x/vulndb@latest +stdout 'Origin' + +go list -m -json golang.org/x/website@latest +stdout 'Origin' + +go list -m -json golang.org/x/xerrors@latest +stdout 'Origin' \ No newline at end of file