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:
Diffstat (limited to 'internal/gitaly/linguist/language_stats_test.go')
-rw-r--r--internal/gitaly/linguist/language_stats_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/gitaly/linguist/language_stats_test.go b/internal/gitaly/linguist/language_stats_test.go
index 0656a664f..3417d74ca 100644
--- a/internal/gitaly/linguist/language_stats_test.go
+++ b/internal/gitaly/linguist/language_stats_test.go
@@ -3,6 +3,9 @@
package linguist
import (
+ "compress/zlib"
+ "encoding/json"
+ "fmt"
"os"
"path/filepath"
"testing"
@@ -54,6 +57,29 @@ func TestNewLanguageStats(t *testing.T) {
require.Empty(t, stats.ByFile)
},
},
+ {
+ desc: "incorrect version cache",
+ run: func(t *testing.T, repo *localrepo.Repo, repoPath string) {
+ stats, err := newLanguageStats(repo)
+ require.NoError(t, err)
+
+ stats.Totals["C"] = 555
+ stats.Version = "faulty"
+
+ // Copy save() behavior, but with a faulty version
+ file, err := os.OpenFile(filepath.Join(repoPath, languageStatsFilename), os.O_WRONLY|os.O_CREATE, 0o755)
+ require.NoError(t, err)
+ w := zlib.NewWriter(file)
+ require.NoError(t, json.NewEncoder(w).Encode(stats))
+ require.NoError(t, w.Close())
+ require.NoError(t, file.Sync())
+ require.NoError(t, file.Close())
+
+ newStats, err := newLanguageStats(repo)
+ require.Error(t, err, fmt.Errorf("new language stats version mismatch %s vs %s", languageStatsVersion, "faulty"))
+ require.Empty(t, newStats.Totals)
+ },
+ },
} {
t.Run(tc.desc, func(t *testing.T) {
repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])