diff options
author | Toon Claes <toon@gitlab.com> | 2022-06-23 09:57:30 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2022-07-05 21:40:03 +0300 |
commit | 0c2e47d1b88e54fbea6efad80422135cf9e07bdc (patch) | |
tree | b11d33fd4ae541fa4a263208b172bd3836a71626 | |
parent | 682581c2728f661620b83427f3f409b20f0800b2 (diff) |
linguist: Test language compatibility with go-enrytoon-linguist-be-gone
To make sure we're not breaking things when we'll switch to go-enry for
the language detection, compare the known languages of the linguist gem
with the Go package.
-rw-r--r-- | internal/gitaly/linguist/linguist_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/gitaly/linguist/linguist_test.go b/internal/gitaly/linguist/linguist_test.go index 2de3136a0..6de429e1a 100644 --- a/internal/gitaly/linguist/linguist_test.go +++ b/internal/gitaly/linguist/linguist_test.go @@ -7,6 +7,8 @@ import ( "path/filepath" "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" @@ -25,6 +27,53 @@ func TestMain(m *testing.M) { testhelper.Run(m) } +func TestNew_knownLanguages(t *testing.T) { + cfg := testcfg.Build(t, testcfg.WithRealLinguist()) + gitCmdFactory := gittest.NewCommandFactory(t, cfg) + + linguist, err := New(cfg, gitCmdFactory) + require.NoError(t, err) + + t.Run("by name", func(t *testing.T) { + linguistLanguages := make([]string, 0, len(linguist.colorMap)) + for language := range linguist.colorMap { + linguistLanguages = append(linguistLanguages, language) + } + + enryLanguages := make([]string, 0, len(enrydata.IDByLanguage)) + for language := range enrydata.IDByLanguage { + enryLanguages = append(enryLanguages, language) + } + + require.ElementsMatch(t, linguistLanguages, enryLanguages) + }) + + t.Run("with their color", func(t *testing.T) { + exclude := map[string]struct{}{} + + linguistLanguages := make(map[string]string, len(linguist.colorMap)) + for language, color := range linguist.colorMap { + if color.Color == "" { + exclude[language] = struct{}{} + continue + } + linguistLanguages[language] = color.Color + } + + enryLanguages := make(map[string]string, len(enrydata.IDByLanguage)) + for language := range enrydata.IDByLanguage { + if _, excluded := exclude[language]; excluded { + continue + } + + color := enry.GetColor(language) + enryLanguages[language] = color + } + + require.Equal(t, linguistLanguages, enryLanguages) + }) +} + func TestInstance_Stats(t *testing.T) { testhelper.NewFeatureSets(featureflag.GoLanguageStats). Run(t, testInstanceStats) |