1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-28 08:49:11 +02:00
revive/revivelib/core_internal_test.go

70 lines
1.2 KiB
Go
Raw Normal View History

package revivelib
import (
"testing"
"github.com/mgechev/revive/config"
"github.com/mgechev/revive/lint"
)
func TestReviveCreateInstance(t *testing.T) {
revive := getMockRevive(t)
if revive.config == nil {
t.Fatal("Could not load config.")
}
if revive.maxOpenFiles != 2048 {
t.Fatal("Expected MaxOpenFiles to be 2048")
}
if revive.lintingRules == nil || len(revive.lintingRules) == 0 {
t.Fatal("Linting rules not loaded.")
}
rules := map[string]lint.Rule{}
for _, rule := range revive.lintingRules {
rules[rule.Name()] = rule
}
if _, ok := rules["mock-rule"]; !ok {
t.Fatal("Didn't load mock rule.")
}
if revive.config.ErrorCode != 1 && revive.config.WarningCode != 1 {
t.Fatal("Didn't set the codes in the config instance.")
}
}
type mockRule struct {
}
2022-04-10 11:55:13 +02:00
func (*mockRule) Name() string {
return "mock-rule"
}
func (*mockRule) Apply(_ *lint.File, _ lint.Arguments) []lint.Failure {
return nil
}
func getMockRevive(t *testing.T) *Revive {
t.Helper()
conf, err := config.GetConfig("../defaults.toml")
if err != nil {
t.Fatal(err)
}
revive, err := New(
conf,
true,
2048,
NewExtraRule(&mockRule{}, lint.RuleConfig{}),
)
if err != nil {
t.Fatal(err.Error())
}
return revive
}