]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add 2 scripts test for git sha256 fetching
authorDavid Finkel <david.finkel@gmail.com>
Wed, 14 May 2025 00:54:15 +0000 (20:54 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 20 May 2025 14:59:04 +0000 (07:59 -0700)
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 <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Auto-Submit: Sam Thanawalla <samthanawalla@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
src/cmd/go/internal/modfetch/codehost/git_test.go
src/cmd/go/testdata/script/build_git_sha256_go_get_branch.txt [new file with mode: 0644]
src/cmd/go/testdata/script/build_git_sha256_moddep.txt [new file with mode: 0644]
src/cmd/go/testdata/vcstest/git/gitrepo-sha256.txt

index cf89548f500b392f55b7708adf2c46e6c881463c..e8884abdfedb60136e646e09fa3cd4627b913a9a 100644 (file)
@@ -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 (file)
index 0000000..fa5557b
--- /dev/null
@@ -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 (file)
index 0000000..e5bf209
--- /dev/null
@@ -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
index ae68a9ad8fd95d9a93ef757db5d3974a19159c2e..81b9a71c12593d4f751d8d8d64fb794f948bb16b 100644 (file)
@@ -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