You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

indexer_test.go 913B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package stats
  5. import (
  6. "path/filepath"
  7. "testing"
  8. "time"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/setting"
  11. "gopkg.in/ini.v1"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestMain(m *testing.M) {
  15. models.MainTest(m, filepath.Join("..", "..", ".."))
  16. }
  17. func TestRepoStatsIndex(t *testing.T) {
  18. assert.NoError(t, models.PrepareTestDatabase())
  19. setting.Cfg = ini.Empty()
  20. setting.NewQueueService()
  21. err := Init()
  22. assert.NoError(t, err)
  23. time.Sleep(5 * time.Second)
  24. repo, err := models.GetRepositoryByID(1)
  25. assert.NoError(t, err)
  26. langs, err := repo.GetTopLanguageStats(5)
  27. assert.NoError(t, err)
  28. assert.Len(t, langs, 1)
  29. assert.Equal(t, "other", langs[0].Language)
  30. assert.Equal(t, float32(100), langs[0].Percentage)
  31. }