diff options
| author | 2026-02-20 22:59:14 +0800 | |
|---|---|---|
| committer | 2026-02-20 22:59:14 +0800 | |
| commit | d88c8e20aebd9408df0306e97dffc2896950342d (patch) | |
| tree | 8e137f37fdd9ea673bd622a2b9c9873cd89278fb | |
| parent | objectid: Use _test package for tests (diff) | |
| signature | No signature | |
*: Replace repo with testRepo
| -rw-r--r-- | config/config_test.go | 96 | ||||
| -rw-r--r-- | internal/testgit/repo_cat_file.go | 4 | ||||
| -rw-r--r-- | internal/testgit/repo_commit_tree.go | 6 | ||||
| -rw-r--r-- | internal/testgit/repo_hash_object.go | 6 | ||||
| -rw-r--r-- | internal/testgit/repo_make_commit.go | 6 | ||||
| -rw-r--r-- | internal/testgit/repo_make_single_file_tree.go | 6 | ||||
| -rw-r--r-- | internal/testgit/repo_mktree.go | 6 | ||||
| -rw-r--r-- | internal/testgit/repo_new.go | 6 | ||||
| -rw-r--r-- | internal/testgit/repo_properties.go | 8 | ||||
| -rw-r--r-- | internal/testgit/repo_rev_parse.go | 6 | ||||
| -rw-r--r-- | internal/testgit/repo_run.go | 20 | ||||
| -rw-r--r-- | internal/testgit/repo_tag_annotated.go | 6 | ||||
| -rw-r--r-- | object/blob_parse_test.go | 6 | ||||
| -rw-r--r-- | object/blob_serialize_test.go | 4 | ||||
| -rw-r--r-- | object/commit_parse_test.go | 6 | ||||
| -rw-r--r-- | object/commit_serialize_test.go | 6 | ||||
| -rw-r--r-- | object/tag_parse_test.go | 10 | ||||
| -rw-r--r-- | object/tag_serialize_test.go | 8 | ||||
| -rw-r--r-- | object/tree_helpers_test.go | 16 | ||||
| -rw-r--r-- | object/tree_parse_test.go | 10 | ||||
| -rw-r--r-- | object/tree_serialize_test.go | 6 |
21 files changed, 124 insertions, 124 deletions
diff --git a/config/config_test.go b/config/config_test.go index 8eb2a468..fd929a1f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -11,29 +11,29 @@ import ( "codeberg.org/lindenii/furgit/objectid" ) -func openConfig(t *testing.T, repo *testgit.TestRepo) *os.File { +func openConfig(t *testing.T, testRepo *testgit.TestRepo) *os.File { t.Helper() - cfgFile, err := os.Open(filepath.Join(repo.Dir(), "config")) + cfgFile, err := os.Open(filepath.Join(testRepo.Dir(), "config")) if err != nil { t.Fatalf("failed to open config: %v", err) } return cfgFile } -func gitConfigGet(t *testing.T, repo *testgit.TestRepo, key string) string { +func gitConfigGet(t *testing.T, testRepo *testgit.TestRepo, key string) string { t.Helper() - return repo.Run(t, "config", "--get", key) + return testRepo.Run(t, "config", "--get", key) } func TestConfigAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - repo.Run(t, "config", "core.bare", "true") - repo.Run(t, "config", "core.filemode", "false") - repo.Run(t, "config", "user.name", "Jane Doe") - repo.Run(t, "config", "user.email", "jane@example.org") + testRepo := testgit.NewBareRepo(t, algo) + testRepo.Run(t, "config", "core.bare", "true") + testRepo.Run(t, "config", "core.filemode", "false") + testRepo.Run(t, "config", "user.name", "Jane Doe") + testRepo.Run(t, "config", "user.email", "jane@example.org") - cfgFile := openConfig(t, repo) + cfgFile := openConfig(t, testRepo) defer func() { _ = cfgFile.Close() }() cfg, err := config.ParseConfig(cfgFile) @@ -58,11 +58,11 @@ func TestConfigAgainstGit(t *testing.T) { func TestConfigSubsectionAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - repo.Run(t, "config", "remote.origin.url", "https://example.org/repo.git") - repo.Run(t, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*") + testRepo := testgit.NewBareRepo(t, algo) + testRepo.Run(t, "config", "remote.origin.url", "https://example.org/repo.git") + testRepo.Run(t, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*") - cfgFile := openConfig(t, repo) + cfgFile := openConfig(t, testRepo) defer func() { _ = cfgFile.Close() }() cfg, err := config.ParseConfig(cfgFile) @@ -81,12 +81,12 @@ func TestConfigSubsectionAgainstGit(t *testing.T) { func TestConfigMultiValueAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - repo.Run(t, "config", "--add", "remote.origin.fetch", "+refs/heads/main:refs/remotes/origin/main") - repo.Run(t, "config", "--add", "remote.origin.fetch", "+refs/heads/dev:refs/remotes/origin/dev") - repo.Run(t, "config", "--add", "remote.origin.fetch", "+refs/tags/*:refs/tags/*") + testRepo := testgit.NewBareRepo(t, algo) + testRepo.Run(t, "config", "--add", "remote.origin.fetch", "+refs/heads/main:refs/remotes/origin/main") + testRepo.Run(t, "config", "--add", "remote.origin.fetch", "+refs/heads/dev:refs/remotes/origin/dev") + testRepo.Run(t, "config", "--add", "remote.origin.fetch", "+refs/tags/*:refs/tags/*") - cfgFile := openConfig(t, repo) + cfgFile := openConfig(t, testRepo) defer func() { _ = cfgFile.Close() }() cfg, err := config.ParseConfig(cfgFile) @@ -114,14 +114,14 @@ func TestConfigMultiValueAgainstGit(t *testing.T) { func TestConfigCaseInsensitiveAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - repo.Run(t, "config", "Core.Bare", "true") - repo.Run(t, "config", "CORE.FileMode", "false") + testRepo := testgit.NewBareRepo(t, algo) + testRepo.Run(t, "config", "Core.Bare", "true") + testRepo.Run(t, "config", "CORE.FileMode", "false") - gitVerifyBare := gitConfigGet(t, repo, "core.bare") - gitVerifyFilemode := gitConfigGet(t, repo, "core.filemode") + gitVerifyBare := gitConfigGet(t, testRepo, "core.bare") + gitVerifyFilemode := gitConfigGet(t, testRepo, "core.filemode") - cfgFile := openConfig(t, repo) + cfgFile := openConfig(t, testRepo) defer func() { _ = cfgFile.Close() }() cfg, err := config.ParseConfig(cfgFile) @@ -143,13 +143,13 @@ func TestConfigCaseInsensitiveAgainstGit(t *testing.T) { func TestConfigBooleanAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - repo.Run(t, "config", "test.flag1", "true") - repo.Run(t, "config", "test.flag2", "false") - repo.Run(t, "config", "test.flag3", "yes") - repo.Run(t, "config", "test.flag4", "no") + testRepo := testgit.NewBareRepo(t, algo) + testRepo.Run(t, "config", "test.flag1", "true") + testRepo.Run(t, "config", "test.flag2", "false") + testRepo.Run(t, "config", "test.flag3", "yes") + testRepo.Run(t, "config", "test.flag4", "no") - cfgFile := openConfig(t, repo) + cfgFile := openConfig(t, testRepo) defer func() { _ = cfgFile.Close() }() cfg, err := config.ParseConfig(cfgFile) @@ -161,10 +161,10 @@ func TestConfigBooleanAgainstGit(t *testing.T) { key string want string }{ - {"flag1", gitConfigGet(t, repo, "test.flag1")}, - {"flag2", gitConfigGet(t, repo, "test.flag2")}, - {"flag3", gitConfigGet(t, repo, "test.flag3")}, - {"flag4", gitConfigGet(t, repo, "test.flag4")}, + {"flag1", gitConfigGet(t, testRepo, "test.flag1")}, + {"flag2", gitConfigGet(t, testRepo, "test.flag2")}, + {"flag3", gitConfigGet(t, testRepo, "test.flag3")}, + {"flag4", gitConfigGet(t, testRepo, "test.flag4")}, } for _, tt := range tests { @@ -177,13 +177,13 @@ func TestConfigBooleanAgainstGit(t *testing.T) { func TestConfigComplexValuesAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - repo.Run(t, "config", "test.spaced", "value with spaces") - repo.Run(t, "config", "test.special", "value=with=equals") - repo.Run(t, "config", "test.path", "/path/to/something") - repo.Run(t, "config", "test.number", "12345") + testRepo := testgit.NewBareRepo(t, algo) + testRepo.Run(t, "config", "test.spaced", "value with spaces") + testRepo.Run(t, "config", "test.special", "value=with=equals") + testRepo.Run(t, "config", "test.path", "/path/to/something") + testRepo.Run(t, "config", "test.number", "12345") - cfgFile := openConfig(t, repo) + cfgFile := openConfig(t, testRepo) defer func() { _ = cfgFile.Close() }() cfg, err := config.ParseConfig(cfgFile) @@ -193,7 +193,7 @@ func TestConfigComplexValuesAgainstGit(t *testing.T) { tests := []string{"spaced", "special", "path", "number"} for _, key := range tests { - want := gitConfigGet(t, repo, "test."+key) + want := gitConfigGet(t, testRepo, "test."+key) if got := cfg.Get("test", "", key); got != want { t.Errorf("test.%s: got %q, want %q (from git)", key, got, want) } @@ -203,12 +203,12 @@ func TestConfigComplexValuesAgainstGit(t *testing.T) { func TestConfigEntriesAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - repo.Run(t, "config", "core.bare", "true") - repo.Run(t, "config", "core.filemode", "false") - repo.Run(t, "config", "user.name", "Test User") + testRepo := testgit.NewBareRepo(t, algo) + testRepo.Run(t, "config", "core.bare", "true") + testRepo.Run(t, "config", "core.filemode", "false") + testRepo.Run(t, "config", "user.name", "Test User") - cfgFile := openConfig(t, repo) + cfgFile := openConfig(t, testRepo) defer func() { _ = cfgFile.Close() }() cfg, err := config.ParseConfig(cfgFile) @@ -229,7 +229,7 @@ func TestConfigEntriesAgainstGit(t *testing.T) { } found[key] = true - gitValue := gitConfigGet(t, repo, key) + gitValue := gitConfigGet(t, testRepo, key) if entry.Value != gitValue { t.Errorf("entry %s: got value %q, git has %q", key, entry.Value, gitValue) } diff --git a/internal/testgit/repo_cat_file.go b/internal/testgit/repo_cat_file.go index c905521f..9cc56db6 100644 --- a/internal/testgit/repo_cat_file.go +++ b/internal/testgit/repo_cat_file.go @@ -7,7 +7,7 @@ import ( ) // CatFile returns raw output from git cat-file. -func (repo *TestRepo) CatFile(tb testing.TB, mode string, id objectid.ObjectID) []byte { +func (testRepo *TestRepo) CatFile(tb testing.TB, mode string, id objectid.ObjectID) []byte { tb.Helper() - return repo.RunBytes(tb, "cat-file", mode, id.String()) + return testRepo.RunBytes(tb, "cat-file", mode, id.String()) } diff --git a/internal/testgit/repo_commit_tree.go b/internal/testgit/repo_commit_tree.go index 1b33b5c0..f8d78421 100644 --- a/internal/testgit/repo_commit_tree.go +++ b/internal/testgit/repo_commit_tree.go @@ -7,15 +7,15 @@ import ( ) // CommitTree creates a commit from a tree and message, optionally with parents. -func (repo *TestRepo) CommitTree(tb testing.TB, tree objectid.ObjectID, message string, parents ...objectid.ObjectID) objectid.ObjectID { +func (testRepo *TestRepo) CommitTree(tb testing.TB, tree objectid.ObjectID, message string, parents ...objectid.ObjectID) objectid.ObjectID { tb.Helper() args := []string{"commit-tree", tree.String()} for _, p := range parents { args = append(args, "-p", p.String()) } args = append(args, "-m", message) - hex := repo.Run(tb, args...) - id, err := objectid.ParseHex(repo.algo, hex) + hex := testRepo.Run(tb, args...) + id, err := objectid.ParseHex(testRepo.algo, hex) if err != nil { tb.Fatalf("parse commit-tree output %q: %v", hex, err) } diff --git a/internal/testgit/repo_hash_object.go b/internal/testgit/repo_hash_object.go index b21e1231..10a05381 100644 --- a/internal/testgit/repo_hash_object.go +++ b/internal/testgit/repo_hash_object.go @@ -7,10 +7,10 @@ import ( ) // HashObject hashes and writes an object and returns its object ID. -func (repo *TestRepo) HashObject(tb testing.TB, objType string, body []byte) objectid.ObjectID { +func (testRepo *TestRepo) HashObject(tb testing.TB, objType string, body []byte) objectid.ObjectID { tb.Helper() - hex := repo.RunInput(tb, body, "hash-object", "-t", objType, "-w", "--stdin") - id, err := objectid.ParseHex(repo.algo, hex) + hex := testRepo.RunInput(tb, body, "hash-object", "-t", objType, "-w", "--stdin") + id, err := objectid.ParseHex(testRepo.algo, hex) if err != nil { tb.Fatalf("parse git hash-object output %q: %v", hex, err) } diff --git a/internal/testgit/repo_make_commit.go b/internal/testgit/repo_make_commit.go index 35619334..a569dfb1 100644 --- a/internal/testgit/repo_make_commit.go +++ b/internal/testgit/repo_make_commit.go @@ -7,9 +7,9 @@ import ( ) // MakeCommit creates a commit over a single-file tree and returns (blobID, treeID, commitID). -func (repo *TestRepo) MakeCommit(tb testing.TB, message string) (objectid.ObjectID, objectid.ObjectID, objectid.ObjectID) { +func (testRepo *TestRepo) MakeCommit(tb testing.TB, message string) (objectid.ObjectID, objectid.ObjectID, objectid.ObjectID) { tb.Helper() - blobID, treeID := repo.MakeSingleFileTree(tb, "file.txt", []byte("commit-body\n")) - commitID := repo.CommitTree(tb, treeID, message) + blobID, treeID := testRepo.MakeSingleFileTree(tb, "file.txt", []byte("commit-body\n")) + commitID := testRepo.CommitTree(tb, treeID, message) return blobID, treeID, commitID } diff --git a/internal/testgit/repo_make_single_file_tree.go b/internal/testgit/repo_make_single_file_tree.go index a0ccce9b..7c53c658 100644 --- a/internal/testgit/repo_make_single_file_tree.go +++ b/internal/testgit/repo_make_single_file_tree.go @@ -8,10 +8,10 @@ import ( ) // MakeSingleFileTree writes one blob and one tree entry for it and returns (blobID, treeID). -func (repo *TestRepo) MakeSingleFileTree(tb testing.TB, fileName string, fileContent []byte) (objectid.ObjectID, objectid.ObjectID) { +func (testRepo *TestRepo) MakeSingleFileTree(tb testing.TB, fileName string, fileContent []byte) (objectid.ObjectID, objectid.ObjectID) { tb.Helper() - blobID := repo.HashObject(tb, "blob", fileContent) + blobID := testRepo.HashObject(tb, "blob", fileContent) treeInput := fmt.Sprintf("100644 blob %s\t%s\n", blobID.String(), fileName) - treeID := repo.Mktree(tb, treeInput) + treeID := testRepo.Mktree(tb, treeInput) return blobID, treeID } diff --git a/internal/testgit/repo_mktree.go b/internal/testgit/repo_mktree.go index 0d3f0ea7..34e6388d 100644 --- a/internal/testgit/repo_mktree.go +++ b/internal/testgit/repo_mktree.go @@ -7,10 +7,10 @@ import ( ) // Mktree creates a tree from textual mktree input and returns its ID. -func (repo *TestRepo) Mktree(tb testing.TB, input string) objectid.ObjectID { +func (testRepo *TestRepo) Mktree(tb testing.TB, input string) objectid.ObjectID { tb.Helper() - hex := repo.RunInput(tb, []byte(input), "mktree") - id, err := objectid.ParseHex(repo.algo, hex) + hex := testRepo.RunInput(tb, []byte(input), "mktree") + id, err := objectid.ParseHex(testRepo.algo, hex) if err != nil { tb.Fatalf("parse mktree output %q: %v", hex, err) } diff --git a/internal/testgit/repo_new.go b/internal/testgit/repo_new.go index 308d8156..8908c8c0 100644 --- a/internal/testgit/repo_new.go +++ b/internal/testgit/repo_new.go @@ -31,7 +31,7 @@ func newRepo(tb testing.TB, algo objectid.Algorithm, bare bool) *TestRepo { } tb.Cleanup(func() { _ = os.RemoveAll(dir) }) - repo := &TestRepo{ + testRepo := &TestRepo{ dir: dir, algo: algo, env: append(os.Environ(), @@ -51,6 +51,6 @@ func newRepo(tb testing.TB, algo objectid.Algorithm, bare bool) *TestRepo { args = append(args, "--bare") } args = append(args, dir) - repo.runBytes(tb, nil, "", args...) - return repo + testRepo.runBytes(tb, nil, "", args...) + return testRepo } diff --git a/internal/testgit/repo_properties.go b/internal/testgit/repo_properties.go index a25c329c..47123ee8 100644 --- a/internal/testgit/repo_properties.go +++ b/internal/testgit/repo_properties.go @@ -3,11 +3,11 @@ package testgit import "codeberg.org/lindenii/furgit/objectid" // Dir returns the repository directory path. -func (repo *TestRepo) Dir() string { - return repo.dir +func (testRepo *TestRepo) Dir() string { + return testRepo.dir } // Algorithm returns the object ID algorithm configured for this repository. -func (repo *TestRepo) Algorithm() objectid.Algorithm { - return repo.algo +func (testRepo *TestRepo) Algorithm() objectid.Algorithm { + return testRepo.algo } diff --git a/internal/testgit/repo_rev_parse.go b/internal/testgit/repo_rev_parse.go index d545f97b..bebdfa8e 100644 --- a/internal/testgit/repo_rev_parse.go +++ b/internal/testgit/repo_rev_parse.go @@ -7,10 +7,10 @@ import ( ) // RevParse resolves rev expressions to object IDs. -func (repo *TestRepo) RevParse(tb testing.TB, spec string) objectid.ObjectID { +func (testRepo *TestRepo) RevParse(tb testing.TB, spec string) objectid.ObjectID { tb.Helper() - hex := repo.Run(tb, "rev-parse", spec) - id, err := objectid.ParseHex(repo.algo, hex) + hex := testRepo.Run(tb, "rev-parse", spec) + id, err := objectid.ParseHex(testRepo.algo, hex) if err != nil { tb.Fatalf("parse rev-parse output %q: %v", hex, err) } diff --git a/internal/testgit/repo_run.go b/internal/testgit/repo_run.go index 66222569..aafcc923 100644 --- a/internal/testgit/repo_run.go +++ b/internal/testgit/repo_run.go @@ -8,36 +8,36 @@ import ( ) // Run executes git and returns trimmed textual output. -func (repo *TestRepo) Run(tb testing.TB, args ...string) string { +func (testRepo *TestRepo) Run(tb testing.TB, args ...string) string { tb.Helper() - out := repo.runBytes(tb, nil, repo.dir, args...) + out := testRepo.runBytes(tb, nil, testRepo.dir, args...) return strings.TrimSpace(string(out)) } // RunBytes executes git and returns raw output bytes. -func (repo *TestRepo) RunBytes(tb testing.TB, args ...string) []byte { +func (testRepo *TestRepo) RunBytes(tb testing.TB, args ...string) []byte { tb.Helper() - return repo.runBytes(tb, nil, repo.dir, args...) + return testRepo.runBytes(tb, nil, testRepo.dir, args...) } // RunInput executes git with stdin and returns trimmed textual output. -func (repo *TestRepo) RunInput(tb testing.TB, stdin []byte, args ...string) string { +func (testRepo *TestRepo) RunInput(tb testing.TB, stdin []byte, args ...string) string { tb.Helper() - out := repo.runBytes(tb, stdin, repo.dir, args...) + out := testRepo.runBytes(tb, stdin, testRepo.dir, args...) return strings.TrimSpace(string(out)) } // RunInputBytes executes git with stdin and returns raw output bytes. -func (repo *TestRepo) RunInputBytes(tb testing.TB, stdin []byte, args ...string) []byte { +func (testRepo *TestRepo) RunInputBytes(tb testing.TB, stdin []byte, args ...string) []byte { tb.Helper() - return repo.runBytes(tb, stdin, repo.dir, args...) + return testRepo.runBytes(tb, stdin, testRepo.dir, args...) } -func (repo *TestRepo) runBytes(tb testing.TB, stdin []byte, dir string, args ...string) []byte { +func (testRepo *TestRepo) runBytes(tb testing.TB, stdin []byte, dir string, args ...string) []byte { tb.Helper() cmd := exec.Command("git", args...) cmd.Dir = dir - cmd.Env = repo.env + cmd.Env = testRepo.env if stdin != nil { cmd.Stdin = bytes.NewReader(stdin) } diff --git a/internal/testgit/repo_tag_annotated.go b/internal/testgit/repo_tag_annotated.go index 3db6cee9..a3ffafa6 100644 --- a/internal/testgit/repo_tag_annotated.go +++ b/internal/testgit/repo_tag_annotated.go @@ -8,8 +8,8 @@ import ( ) // TagAnnotated creates an annotated tag object and returns the resulting tag object ID. -func (repo *TestRepo) TagAnnotated(tb testing.TB, name string, target objectid.ObjectID, message string) objectid.ObjectID { +func (testRepo *TestRepo) TagAnnotated(tb testing.TB, name string, target objectid.ObjectID, message string) objectid.ObjectID { tb.Helper() - repo.Run(tb, "tag", "-a", name, target.String(), "-m", message) - return repo.RevParse(tb, fmt.Sprintf("refs/tags/%s", name)) + testRepo.Run(tb, "tag", "-a", name, target.String(), "-m", message) + return testRepo.RevParse(tb, fmt.Sprintf("refs/tags/%s", name)) } diff --git a/object/blob_parse_test.go b/object/blob_parse_test.go index ad0f7ef3..ea0a279e 100644 --- a/object/blob_parse_test.go +++ b/object/blob_parse_test.go @@ -11,11 +11,11 @@ import ( func TestBlobParseFromGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewBareRepo(t, algo) body := []byte("hello\nblob\n") - blobID := repo.HashObject(t, "blob", body) + blobID := testRepo.HashObject(t, "blob", body) - rawBody := repo.CatFile(t, "blob", blobID) + rawBody := testRepo.CatFile(t, "blob", blobID) blob, err := object.ParseBlob(rawBody) if err != nil { t.Fatalf("ParseBlob: %v", err) diff --git a/object/blob_serialize_test.go b/object/blob_serialize_test.go index 07811365..4853d980 100644 --- a/object/blob_serialize_test.go +++ b/object/blob_serialize_test.go @@ -10,9 +10,9 @@ import ( func TestBlobSerialize(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewBareRepo(t, algo) body := []byte("hello\nblob\n") - wantID := repo.HashObject(t, "blob", body) + wantID := testRepo.HashObject(t, "blob", body) blob := &object.Blob{Data: body} rawObj, err := blob.SerializeWithHeader() diff --git a/object/commit_parse_test.go b/object/commit_parse_test.go index e1bfb3d1..66061f73 100644 --- a/object/commit_parse_test.go +++ b/object/commit_parse_test.go @@ -11,10 +11,10 @@ import ( func TestCommitParseFromGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - _, treeID, commitID := repo.MakeCommit(t, "subject\n\nbody") + testRepo := testgit.NewBareRepo(t, algo) + _, treeID, commitID := testRepo.MakeCommit(t, "subject\n\nbody") - rawBody := repo.CatFile(t, "commit", commitID) + rawBody := testRepo.CatFile(t, "commit", commitID) commit, err := object.ParseCommit(rawBody, algo) if err != nil { t.Fatalf("ParseCommit: %v", err) diff --git a/object/commit_serialize_test.go b/object/commit_serialize_test.go index 5f4cf0cf..9067d511 100644 --- a/object/commit_serialize_test.go +++ b/object/commit_serialize_test.go @@ -10,10 +10,10 @@ import ( func TestCommitSerialize(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - _, _, commitID := repo.MakeCommit(t, "subject\n\nbody") + testRepo := testgit.NewBareRepo(t, algo) + _, _, commitID := testRepo.MakeCommit(t, "subject\n\nbody") - rawBody := repo.CatFile(t, "commit", commitID) + rawBody := testRepo.CatFile(t, "commit", commitID) commit, err := object.ParseCommit(rawBody, algo) if err != nil { t.Fatalf("ParseCommit: %v", err) diff --git a/object/tag_parse_test.go b/object/tag_parse_test.go index 84d29069..4131e3f1 100644 --- a/object/tag_parse_test.go +++ b/object/tag_parse_test.go @@ -6,17 +6,17 @@ import ( "codeberg.org/lindenii/furgit/internal/testgit" "codeberg.org/lindenii/furgit/object" - "codeberg.org/lindenii/furgit/objecttype" "codeberg.org/lindenii/furgit/objectid" + "codeberg.org/lindenii/furgit/objecttype" ) func TestTagParseFromGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - _, _, commitID := repo.MakeCommit(t, "subject\n\nbody") - tagID := repo.TagAnnotated(t, "v1", commitID, "tag message") + testRepo := testgit.NewBareRepo(t, algo) + _, _, commitID := testRepo.MakeCommit(t, "subject\n\nbody") + tagID := testRepo.TagAnnotated(t, "v1", commitID, "tag message") - rawBody := repo.CatFile(t, "tag", tagID) + rawBody := testRepo.CatFile(t, "tag", tagID) tag, err := object.ParseTag(rawBody, algo) if err != nil { t.Fatalf("ParseTag: %v", err) diff --git a/object/tag_serialize_test.go b/object/tag_serialize_test.go index 435259b4..3f1f8b0b 100644 --- a/object/tag_serialize_test.go +++ b/object/tag_serialize_test.go @@ -10,11 +10,11 @@ import ( func TestTagSerialize(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - _, _, commitID := repo.MakeCommit(t, "subject\n\nbody") - tagID := repo.TagAnnotated(t, "v1", commitID, "tag message") + testRepo := testgit.NewBareRepo(t, algo) + _, _, commitID := testRepo.MakeCommit(t, "subject\n\nbody") + tagID := testRepo.TagAnnotated(t, "v1", commitID, "tag message") - rawBody := repo.CatFile(t, "tag", tagID) + rawBody := testRepo.CatFile(t, "tag", tagID) tag, err := object.ParseTag(rawBody, algo) if err != nil { t.Fatalf("ParseTag: %v", err) diff --git a/object/tree_helpers_test.go b/object/tree_helpers_test.go index ce7160d6..539d7542 100644 --- a/object/tree_helpers_test.go +++ b/object/tree_helpers_test.go @@ -61,20 +61,20 @@ func gitLsTreeNames(out []byte) [][]byte { return names } -func adversarialRootEntries(t *testing.T, repo *testgit.TestRepo) []object.TreeEntry { +func adversarialRootEntries(t *testing.T, testRepo *testgit.TestRepo) []object.TreeEntry { t.Helper() - blobA := repo.HashObject(t, "blob", []byte("blob-A\n")) - blobB := repo.HashObject(t, "blob", []byte("blob-B\n")) - blobC := repo.HashObject(t, "blob", []byte("blob-C\n")) + blobA := testRepo.HashObject(t, "blob", []byte("blob-A\n")) + blobB := testRepo.HashObject(t, "blob", []byte("blob-B\n")) + blobC := testRepo.HashObject(t, "blob", []byte("blob-C\n")) - subDirA := repo.Mktree(t, + subDirA := testRepo.Mktree(t, fmt.Sprintf("100644 blob %s\tnested-a.txt\n100755 blob %s\trun-a.sh\n", blobA.String(), blobB.String())) - subDirB := repo.Mktree(t, + subDirB := testRepo.Mktree(t, fmt.Sprintf("100644 blob %s\tnested-b.txt\n100644 blob %s\tz-last\n", blobB.String(), blobC.String())) - subDirC := repo.Mktree(t, + subDirC := testRepo.Mktree(t, fmt.Sprintf("120000 blob %s\tlink-c\n100644 blob %s\tchild\n", blobC.String(), blobA.String())) - subDirD := repo.Mktree(t, + subDirD := testRepo.Mktree(t, fmt.Sprintf("100644 blob %s\tleaf\n", blobA.String())) return []object.TreeEntry{ diff --git a/object/tree_parse_test.go b/object/tree_parse_test.go index 09c396e3..e1c81d58 100644 --- a/object/tree_parse_test.go +++ b/object/tree_parse_test.go @@ -11,8 +11,8 @@ import ( func TestTreeParseFromGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - entries := adversarialRootEntries(t, repo) + testRepo := testgit.NewBareRepo(t, algo) + entries := adversarialRootEntries(t, testRepo) inserted := &object.Tree{} for _, entry := range entries { if err := inserted.InsertEntry(entry); err != nil { @@ -20,9 +20,9 @@ func TestTreeParseFromGit(t *testing.T) { } } - treeID := repo.Mktree(t, buildGitMktreeInput(inserted.Entries)) + treeID := testRepo.Mktree(t, buildGitMktreeInput(inserted.Entries)) - rawBody := repo.CatFile(t, "tree", treeID) + rawBody := testRepo.CatFile(t, "tree", treeID) tree, err := object.ParseTree(rawBody, algo) if err != nil { t.Fatalf("ParseTree: %v", err) @@ -40,7 +40,7 @@ func TestTreeParseFromGit(t *testing.T) { } } - lsNames := gitLsTreeNames(repo.RunBytes(t, "ls-tree", "--name-only", "-z", treeID.String())) + lsNames := gitLsTreeNames(testRepo.RunBytes(t, "ls-tree", "--name-only", "-z", treeID.String())) if len(lsNames) != len(tree.Entries) { t.Fatalf("ls-tree names = %d, want %d", len(lsNames), len(tree.Entries)) } diff --git a/object/tree_serialize_test.go b/object/tree_serialize_test.go index 462eff9d..8e84a67b 100644 --- a/object/tree_serialize_test.go +++ b/object/tree_serialize_test.go @@ -10,8 +10,8 @@ import ( func TestTreeSerialize(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - repo := testgit.NewBareRepo(t, algo) - entries := adversarialRootEntries(t, repo) + testRepo := testgit.NewBareRepo(t, algo) + entries := adversarialRootEntries(t, testRepo) tree := &object.Tree{} for i := len(entries) - 1; i >= 0; i-- { @@ -45,7 +45,7 @@ func TestTreeSerialize(t *testing.T) { t.Fatalf("Entry(%q) should exist after reinsert", removed.Name) } - wantTreeID := repo.Mktree(t, buildGitMktreeInput(tree.Entries)) + wantTreeID := testRepo.Mktree(t, buildGitMktreeInput(tree.Entries)) rawObj, err := tree.SerializeWithHeader() if err != nil { |
