-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgolint_test.go
More file actions
59 lines (48 loc) · 1.49 KB
/
golint_test.go
File metadata and controls
59 lines (48 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package lint_test
import (
"testing"
lint "github.com/channel-io/cht-go-lint"
)
func TestRunGoLintDisabled(t *testing.T) {
rpt := lint.NewReport()
// nil GoLint config — should be a no-op
cfg := &lint.Config{Root: t.TempDir()}
if err := lint.RunGoLint(cfg, rpt, false); err != nil {
t.Errorf("expected nil error for nil GoLint, got: %v", err)
}
if rpt.Total() != 0 {
t.Errorf("expected 0 violations, got %d", rpt.Total())
}
// Disabled GoLint config — should be a no-op
cfg.GoLint = &lint.GoLintConfig{Enabled: false}
if err := lint.RunGoLint(cfg, rpt, false); err != nil {
t.Errorf("expected nil error for disabled GoLint, got: %v", err)
}
if rpt.Total() != 0 {
t.Errorf("expected 0 violations, got %d", rpt.Total())
}
}
func TestRunGoLintDisabledWithFix(t *testing.T) {
rpt := lint.NewReport()
// fix=true should still be a no-op when GoLint is disabled
cfg := &lint.Config{Root: t.TempDir()}
if err := lint.RunGoLint(cfg, rpt, true); err != nil {
t.Errorf("expected nil error for nil GoLint with fix, got: %v", err)
}
if rpt.Total() != 0 {
t.Errorf("expected 0 violations, got %d", rpt.Total())
}
}
func TestRunGoLintNotInstalled(t *testing.T) {
rpt := lint.NewReport()
cfg := &lint.Config{
Root: t.TempDir(),
GoLint: &lint.GoLintConfig{Enabled: true},
}
// Set PATH to empty to ensure golangci-lint is not found
t.Setenv("PATH", "")
err := lint.RunGoLint(cfg, rpt, false)
if err == nil {
t.Error("expected error when golangci-lint is not in PATH")
}
}