Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2022-08-05 12:47:16 +0300
committerToon Claes <toon@gitlab.com>2022-08-08 17:49:25 +0300
commita847bafa7f23bf2dd9852f3959692eaa06df8756 (patch)
tree2e8d2022b30af59797e0be18d5d6733a4e7f0f91
parente5f57d179e81aaad65fcf31bcae3473e87c2a5d1 (diff)
linguist: Change tests to use dynamically created commits
Don't start of with a pre-existing repo, but instead build the commits dynamically on demand. This prepares for testing with the SHA256 object hashes.
-rw-r--r--internal/gitaly/linguist/language_stats_test.go8
-rw-r--r--internal/gitaly/linguist/linguist_test.go35
2 files changed, 30 insertions, 13 deletions
diff --git a/internal/gitaly/linguist/language_stats_test.go b/internal/gitaly/linguist/language_stats_test.go
index a17ceeb78..7e8a44d3b 100644
--- a/internal/gitaly/linguist/language_stats_test.go
+++ b/internal/gitaly/linguist/language_stats_test.go
@@ -17,7 +17,7 @@ func TestNewLanguageStats(t *testing.T) {
t.Parallel()
cfg := testcfg.Build(t)
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
t.Run("non-existing cache", func(t *testing.T) {
@@ -51,7 +51,7 @@ func TestLanguageStats_add(t *testing.T) {
t.Parallel()
cfg := testcfg.Build(t)
- repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
for _, tc := range []struct {
@@ -118,7 +118,7 @@ func TestLanguageStats_drop(t *testing.T) {
t.Parallel()
cfg := testcfg.Build(t)
- repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
for _, tc := range []struct {
@@ -173,7 +173,7 @@ func TestLanguageStats_save(t *testing.T) {
t.Parallel()
cfg := testcfg.Build(t)
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
s, err := newLanguageStats(repo)
diff --git a/internal/gitaly/linguist/linguist_test.go b/internal/gitaly/linguist/linguist_test.go
index dd663ab57..85c393e7a 100644
--- a/internal/gitaly/linguist/linguist_test.go
+++ b/internal/gitaly/linguist/linguist_test.go
@@ -7,12 +7,11 @@ import (
"encoding/json"
"os"
"path/filepath"
+ "strings"
"testing"
"github.com/go-enry/go-enry/v2"
enrydata "github.com/go-enry/go-enry/v2/data"
- "github.com/sirupsen/logrus"
- "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
@@ -95,8 +94,6 @@ func testInstanceStats(t *testing.T, ctx context.Context) {
catfileCache := catfile.NewCache(cfg)
t.Cleanup(catfileCache.Stop)
- commitID := git.ObjectID("1e292f8fedd741b75372e19097c76d327140c312")
-
languageStatsFilename := filenameForCache(ctx)
for _, tc := range []struct {
@@ -108,7 +105,14 @@ func testInstanceStats(t *testing.T, ctx context.Context) {
{
desc: "successful",
setup: func(t *testing.T) (*gitalypb.Repository, string, git.ObjectID) {
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries(
+ gittest.TreeEntry{Path: "webpack.coffee", Mode: "100644", Content: strings.Repeat("a", 107)},
+ gittest.TreeEntry{Path: "show_user.html", Mode: "100644", Content: strings.Repeat("a", 349)},
+ gittest.TreeEntry{Path: "api.javascript", Mode: "100644", Content: strings.Repeat("a", 1014)},
+ gittest.TreeEntry{Path: "application.rb", Mode: "100644", Content: strings.Repeat("a", 2943)},
+ ))
+
return repoProto, repoPath, commitID
},
expectedStats: map[string]uint64{
@@ -121,7 +125,13 @@ func testInstanceStats(t *testing.T, ctx context.Context) {
{
desc: "preexisting cache",
setup: func(t *testing.T) (*gitalypb.Repository, string, git.ObjectID) {
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries(
+ gittest.TreeEntry{Path: "webpack.coffee", Mode: "100644", Content: strings.Repeat("a", 107)},
+ gittest.TreeEntry{Path: "show_user.html", Mode: "100644", Content: strings.Repeat("a", 349)},
+ gittest.TreeEntry{Path: "api.javascript", Mode: "100644", Content: strings.Repeat("a", 1014)},
+ gittest.TreeEntry{Path: "application.rb", Mode: "100644", Content: strings.Repeat("a", 2943)},
+ ))
repo := localrepo.NewTestRepo(t, cfg, repoProto)
// We simply run the linguist once before so that it can already
@@ -145,7 +155,13 @@ func testInstanceStats(t *testing.T, ctx context.Context) {
{
desc: "corrupted cache",
setup: func(t *testing.T) (*gitalypb.Repository, string, git.ObjectID) {
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries(
+ gittest.TreeEntry{Path: "webpack.coffee", Mode: "100644", Content: strings.Repeat("a", 107)},
+ gittest.TreeEntry{Path: "show_user.html", Mode: "100644", Content: strings.Repeat("a", 349)},
+ gittest.TreeEntry{Path: "api.javascript", Mode: "100644", Content: strings.Repeat("a", 1014)},
+ gittest.TreeEntry{Path: "application.rb", Mode: "100644", Content: strings.Repeat("a", 2943)},
+ ))
require.NoError(t, os.WriteFile(filepath.Join(repoPath, languageStatsFilename), []byte("garbage"), 0o644))
@@ -192,7 +208,7 @@ func testInstanceStats(t *testing.T, ctx context.Context) {
repoPath := filepath.Join(testhelper.TempDir(t), "nonexistent")
repoProto := &gitalypb.Repository{StorageName: cfg.Storages[0].Name, RelativePath: "nonexistent"}
- return repoProto, repoPath, commitID
+ return repoProto, repoPath, git.ObjectID("b1bb1d1b0b1d1b00")
},
expectedErr: "GetRepoPath: not a git repository",
},
@@ -200,7 +216,8 @@ func testInstanceStats(t *testing.T, ctx context.Context) {
desc: "missing commit",
setup: func(t *testing.T) (*gitalypb.Repository, string, git.ObjectID) {
repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
- return repoProto, repoPath, commitID
+
+ return repoProto, repoPath, git.ObjectID("b1bb1d1b0b1d1b00")
},
expectedErr: "linguist",
},