diff options
author | John Cai <johncai86@gmail.com> | 2022-12-30 00:32:45 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2023-01-09 20:40:14 +0300 |
commit | a0ec0b89bbd0ffad1b5e56efe9cd9c0c18818537 (patch) | |
tree | e749d63571c0b4cc6bf275bf48099b57c9b3b812 | |
parent | bf9c2ffc098cc28a2c1fa3ab98931eab511063bf (diff) |
localrepo: Add MustWriteBlob helper
Add a helper for writing test blobs in the localrepo. Going forward,
this is meant to be the function to use in tests rather than the gittest
package.
-rw-r--r-- | internal/git/gittest/objects.go | 1 | ||||
-rw-r--r-- | internal/git/localrepo/objects.go | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/internal/git/gittest/objects.go b/internal/git/gittest/objects.go index d7499868f..7540b83f7 100644 --- a/internal/git/gittest/objects.go +++ b/internal/git/gittest/objects.go @@ -78,6 +78,7 @@ func WriteBlobs(tb testing.TB, cfg config.Cfg, testRepoPath string, n int) []str } // WriteBlob writes the given contents as a blob into the repository and returns its OID. +// Deprecated: internal/git/localrepo package should e used for writing commits func WriteBlob(tb testing.TB, cfg config.Cfg, testRepoPath string, contents []byte) git.ObjectID { hex := text.ChompBytes(ExecOpts(tb, cfg, ExecConfig{Stdin: bytes.NewReader(contents)}, "-C", testRepoPath, "hash-object", "-w", "--stdin", diff --git a/internal/git/localrepo/objects.go b/internal/git/localrepo/objects.go index d34f6b11e..170326d1c 100644 --- a/internal/git/localrepo/objects.go +++ b/internal/git/localrepo/objects.go @@ -7,13 +7,16 @@ import ( "fmt" "io" "strings" + "testing" "time" + "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v15/internal/command" "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile" "gitlab.com/gitlab-org/gitaly/v15/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag" + "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" ) @@ -321,3 +324,11 @@ func (repo *Repo) IsAncestor(ctx context.Context, parent, child git.Revision) (b return true, nil } + +// WriteTestBlob is used to write blobs to repositories in tests +func MustWriteBlob(tb testing.TB, repo *Repo, path, content string) git.ObjectID { + oid, err := repo.WriteBlob(testhelper.Context(tb), path, bytes.NewBufferString(content)) + require.NoError(tb, err) + + return oid +} |