summaryrefslogtreecommitdiffstats
path: root/modules/indexer/stats/indexer_test.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2020-02-11 10:34:17 +0100
committerGitHub <noreply@github.com>2020-02-11 10:34:17 +0100
commitad2642a8aac9facb217a8471df1d3e00f1214e92 (patch)
treeea198b2b3130d22bb60886b6ba0a1df352f160ff /modules/indexer/stats/indexer_test.go
parentRestore graceful restart on SIGHUP (#10224) (diff)
downloadforgejo-ad2642a8aac9facb217a8471df1d3e00f1214e92.tar.xz
forgejo-ad2642a8aac9facb217a8471df1d3e00f1214e92.zip
Language statistics bar for repositories (#8037)
* Implementation for calculating language statistics Impement saving code language statistics to database Implement rendering langauge stats Add primary laguage to show in repository list Implement repository stats indexer queue Add indexer test Refactor to use queue module * Do not timeout for queues
Diffstat (limited to 'modules/indexer/stats/indexer_test.go')
-rw-r--r--modules/indexer/stats/indexer_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/indexer/stats/indexer_test.go b/modules/indexer/stats/indexer_test.go
new file mode 100644
index 0000000000..29d0f6dbe4
--- /dev/null
+++ b/modules/indexer/stats/indexer_test.go
@@ -0,0 +1,42 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package stats
+
+import (
+ "path/filepath"
+ "testing"
+ "time"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/setting"
+
+ "gopkg.in/ini.v1"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestMain(m *testing.M) {
+ models.MainTest(m, filepath.Join("..", "..", ".."))
+}
+
+func TestRepoStatsIndex(t *testing.T) {
+ assert.NoError(t, models.PrepareTestDatabase())
+ setting.Cfg = ini.Empty()
+
+ setting.NewQueueService()
+
+ err := Init()
+ assert.NoError(t, err)
+
+ time.Sleep(5 * time.Second)
+
+ repo, err := models.GetRepositoryByID(1)
+ assert.NoError(t, err)
+ langs, err := repo.GetTopLanguageStats(5)
+ assert.NoError(t, err)
+ assert.Len(t, langs, 1)
+ assert.Equal(t, "other", langs[0].Language)
+ assert.Equal(t, float32(100), langs[0].Percentage)
+}