aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/vcs/git_test_util.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2026-01-06 19:16:54 +0100
committerAleksandr Nogikh <nogikh@google.com>2026-01-09 14:28:59 +0000
commitab680254a62d631fbad7921aa157e4cc37c1dbc6 (patch)
treed0c50112732785cbfbc70044e832a530539b80a0 /pkg/vcs/git_test_util.go
parenta45480436715f68eac7cc949da964ee2b73ef172 (diff)
pkg/vcs: extend git testing helpers
Add a commitChangeset() method to simplify setting up repository states in tests.
Diffstat (limited to 'pkg/vcs/git_test_util.go')
-rw-r--r--pkg/vcs/git_test_util.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/vcs/git_test_util.go b/pkg/vcs/git_test_util.go
index 9d5ef1edc..012972abc 100644
--- a/pkg/vcs/git_test_util.go
+++ b/pkg/vcs/git_test_util.go
@@ -5,6 +5,7 @@ package vcs
import (
"fmt"
+ "os"
"path/filepath"
"strings"
"testing"
@@ -77,11 +78,35 @@ func (repo *TestRepo) CommitFileChange(branch, change string) {
}
func (repo *TestRepo) CommitChange(description string) *Commit {
+ return repo.commitChangeset(description)
+}
+
+type writeFile struct {
+ File string
+ Content string
+}
+
+func (wf *writeFile) Apply(repo *TestRepo) error {
+ err := os.WriteFile(filepath.Join(repo.Dir, wf.File), []byte(wf.Content), 0644)
+ if err != nil {
+ return err
+ }
+ repo.Git("add", wf.File)
+ return nil
+}
+
+func (repo *TestRepo) commitChangeset(description string, actions ...writeFile) *Commit {
+ for i, action := range actions {
+ if err := action.Apply(repo); err != nil {
+ repo.t.Fatalf("failed to apply action %d: %v", i, err)
+ }
+ }
repo.Git("commit", "--allow-empty", "-m", description)
com, err := repo.repo.Commit(HEAD)
if err != nil {
repo.t.Fatal(err)
}
+ repo.t.Logf("%q's hash is %s", description, com.Hash)
return com
}