From: David Finkel Date: Wed, 14 May 2025 00:54:15 +0000 (-0400) Subject: cmd/go: add 2 scripts test for git sha256 fetching X-Git-Tag: go1.25rc1~213 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7b91ec07eb2938f964579e20bef09e418c5091aa;p=gostls13.git cmd/go: add 2 scripts test for git sha256 fetching Fast follow to golang.org/cl/636475 with a couple script tests that build/runs a module that depends on a function inside a git repo using sha256 hashes. (one with go get of a branch-name and the other configuring go.mod directly) Change-Id: Ief6c7efaf6d5c066dc54a3e4a63aad109f625abe Reviewed-on: https://go-review.googlesource.com/c/go/+/672435 Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob Auto-Submit: Sam Thanawalla LUCI-TryBot-Result: Go LUCI Reviewed-by: Sam Thanawalla --- diff --git a/src/cmd/go/internal/modfetch/codehost/git_test.go b/src/cmd/go/internal/modfetch/codehost/git_test.go index cf89548f50..e8884abdfe 100644 --- a/src/cmd/go/internal/modfetch/codehost/git_test.go +++ b/src/cmd/go/internal/modfetch/codehost/git_test.go @@ -245,6 +245,7 @@ func TestTags(t *testing.T) { {gitsha256repo, "", []Tag{ {"v1.2.3", "47b8b51b2a2d9d5caa3d460096c4e01f05700ce3a9390deb54400bd508214c5c"}, {"v1.2.4-annotated", "47b8b51b2a2d9d5caa3d460096c4e01f05700ce3a9390deb54400bd508214c5c"}, + {"v1.3.0", "a9157cad2aa6dc2f78aa31fced5887f04e758afa8703f04d0178702ebf04ee17"}, {"v2.0.1", "b7550fd9d2129c724c39ae0536e8b2fae4364d8c82bb8b0880c9b71f67295d09"}, {"v2.0.2", "1401e4e1fdb4169b51d44a1ff62af63ccc708bf5c12d15051268b51bbb6cbd82"}, {"v2.3", "b7550fd9d2129c724c39ae0536e8b2fae4364d8c82bb8b0880c9b71f67295d09"}, @@ -252,6 +253,7 @@ func TestTags(t *testing.T) { {gitsha256repo, "v", []Tag{ {"v1.2.3", "47b8b51b2a2d9d5caa3d460096c4e01f05700ce3a9390deb54400bd508214c5c"}, {"v1.2.4-annotated", "47b8b51b2a2d9d5caa3d460096c4e01f05700ce3a9390deb54400bd508214c5c"}, + {"v1.3.0", "a9157cad2aa6dc2f78aa31fced5887f04e758afa8703f04d0178702ebf04ee17"}, {"v2.0.1", "b7550fd9d2129c724c39ae0536e8b2fae4364d8c82bb8b0880c9b71f67295d09"}, {"v2.0.2", "1401e4e1fdb4169b51d44a1ff62af63ccc708bf5c12d15051268b51bbb6cbd82"}, {"v2.3", "b7550fd9d2129c724c39ae0536e8b2fae4364d8c82bb8b0880c9b71f67295d09"}, @@ -259,6 +261,7 @@ func TestTags(t *testing.T) { {gitsha256repo, "v1", []Tag{ {"v1.2.3", "47b8b51b2a2d9d5caa3d460096c4e01f05700ce3a9390deb54400bd508214c5c"}, {"v1.2.4-annotated", "47b8b51b2a2d9d5caa3d460096c4e01f05700ce3a9390deb54400bd508214c5c"}, + {"v1.3.0", "a9157cad2aa6dc2f78aa31fced5887f04e758afa8703f04d0178702ebf04ee17"}, }}, {gitsha256repo, "2", []Tag{}}, } { diff --git a/src/cmd/go/testdata/script/build_git_sha256_go_get_branch.txt b/src/cmd/go/testdata/script/build_git_sha256_go_get_branch.txt new file mode 100644 index 0000000000..fa5557b21e --- /dev/null +++ b/src/cmd/go/testdata/script/build_git_sha256_go_get_branch.txt @@ -0,0 +1,28 @@ +[short] skip +[!git] skip + +env GOPRIVATE=vcs-test.golang.org + +go get vcs-test.golang.org/go/mod/gitrepo-sha256@basic_module +stderr 'downloading vcs-test\.golang.org/go/mod/gitrepo-sha256 v1.3.0' + +go run . +stdout '1234' + +-- main.go -- +package main + +import ( + "fmt" + + sha256repo "vcs-test.golang.org/go/mod/gitrepo-sha256" +) + +func main() { + fmt.Println(sha256repo.Foobar(1234)) +} + +-- go.mod -- +module test + +go 1.24.3 diff --git a/src/cmd/go/testdata/script/build_git_sha256_moddep.txt b/src/cmd/go/testdata/script/build_git_sha256_moddep.txt new file mode 100644 index 0000000000..e5bf209d89 --- /dev/null +++ b/src/cmd/go/testdata/script/build_git_sha256_moddep.txt @@ -0,0 +1,30 @@ +[short] skip +[!git] skip + +env GOPRIVATE=vcs-test.golang.org + +go mod tidy +stderr 'downloading vcs-test\.golang.org/go/mod/gitrepo-sha256 v1.3.0' + +go run . +stdout '1234' + +-- main.go -- +package main + +import ( + "fmt" + + sha256repo "vcs-test.golang.org/go/mod/gitrepo-sha256" +) + +func main() { + fmt.Println(sha256repo.Foobar(1234)) +} + +-- go.mod -- +module test + +go 1.24.3 + +require vcs-test.golang.org/go/mod/gitrepo-sha256 v1.3.0 diff --git a/src/cmd/go/testdata/vcstest/git/gitrepo-sha256.txt b/src/cmd/go/testdata/vcstest/git/gitrepo-sha256.txt index ae68a9ad8f..81b9a71c12 100644 --- a/src/cmd/go/testdata/vcstest/git/gitrepo-sha256.txt +++ b/src/cmd/go/testdata/vcstest/git/gitrepo-sha256.txt @@ -12,7 +12,7 @@ at 2018-04-17T15:43:22-04:00 unquote '' cp stdout README git add README -git commit -a -m 'empty README' +git commit -m 'empty README' git branch -m main git tag v1.2.3 @@ -22,7 +22,7 @@ git checkout v2 echo 'v2' cp stdout v2 git add v2 -git commit -a -m 'v2' +git commit -m 'v2' git tag v2.3 git tag v2.0.1 git branch v2.3.4 @@ -31,13 +31,13 @@ at 2018-04-17T16:00:19-04:00 echo 'intermediate' cp stdout foo.txt git add foo.txt -git commit -a -m 'intermediate' +git commit -m 'intermediate' at 2018-04-17T16:00:32-04:00 echo 'another' cp stdout another.txt git add another.txt -git commit -a -m 'another' +git commit -m 'another' git tag v2.0.2 at 2018-04-17T16:16:52-04:00 @@ -48,22 +48,44 @@ mkdir v3/sub/dir echo 'v3/sub/dir/file' cp stdout v3/sub/dir/file.txt git add v3 -git commit -a -m 'add v3/sub/dir/file.txt' +git commit -m 'add v3/sub/dir/file.txt' at 2018-04-17T22:23:00-04:00 git checkout main git tag -a v1.2.4-annotated -m 'v1.2.4-annotated' +git switch -c basic_module +git add go.mod foobar.go +git commit -m 'add go.mod & Foobar function' +git tag v1.3.0 +git switch main + git show-ref --tags --heads cmp stdout .git-refs +-- go.mod -- +module vcs-test.golang.org/go/mod/gitrepo-sha256 + +go 1.24.3 + +-- foobar.go -- + +package sha256repo + +// Foobar is the identity function +func Foobar[T any](v T) T { + return v +} + -- .git-refs -- +a9157cad2aa6dc2f78aa31fced5887f04e758afa8703f04d0178702ebf04ee17 refs/heads/basic_module 47b8b51b2a2d9d5caa3d460096c4e01f05700ce3a9390deb54400bd508214c5c refs/heads/main 1401e4e1fdb4169b51d44a1ff62af63ccc708bf5c12d15051268b51bbb6cbd82 refs/heads/v2 b7550fd9d2129c724c39ae0536e8b2fae4364d8c82bb8b0880c9b71f67295d09 refs/heads/v2.3.4 c2a5bbdbeb8b2c82e819a4af94ea59f7d67faeb6df7cb4907c3f0d70836a977b refs/heads/v3 47b8b51b2a2d9d5caa3d460096c4e01f05700ce3a9390deb54400bd508214c5c refs/tags/v1.2.3 f88263be2704531e0f664784b66c2f84dea6d0dc4231cf9c6be482af0400c607 refs/tags/v1.2.4-annotated +a9157cad2aa6dc2f78aa31fced5887f04e758afa8703f04d0178702ebf04ee17 refs/tags/v1.3.0 b7550fd9d2129c724c39ae0536e8b2fae4364d8c82bb8b0880c9b71f67295d09 refs/tags/v2.0.1 1401e4e1fdb4169b51d44a1ff62af63ccc708bf5c12d15051268b51bbb6cbd82 refs/tags/v2.0.2 b7550fd9d2129c724c39ae0536e8b2fae4364d8c82bb8b0880c9b71f67295d09 refs/tags/v2.3