-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommand_test.go
40 lines (31 loc) · 1.16 KB
/
command_test.go
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
package main
import (
"os"
"testing"
codacy "github.com/codacy/codacy-engine-golang-seed/v6"
"github.com/stretchr/testify/assert"
)
func TestParseOutput(t *testing.T) {
reviveOutput := `{"Severity":"warning","Failure":"exported function Public should have comment or be unexported","RuleName":"exported","Category":"comments","Position":{"Start":{"Filename":"foo.go","Offset":39,"Line":7,"Column":1},"End":{"Filename":"foo.go","Offset":105,"Line":9,"Column":2}},"Confidence":1,"ReplacementLine":""}`
parsedOutput := parseOutput(reviveOutput)
expectedOutput := []codacy.Result{
codacy.Issue{
File: "foo.go",
Message: "exported function Public should have comment or be unexported",
PatternID: "exported",
Line: 7,
},
}
assert.Equal(t, expectedOutput, parsedOutput)
}
func TestReviveCommand(t *testing.T) {
filesToAnalyse := []string{"foo.go", "bar.go"}
sourceDir := "/src"
configFile, err := os.CreateTemp(os.TempDir(), "gorevive-")
assert.Nil(t, err)
cmd := reviveCommand(configFile, filesToAnalyse, sourceDir)
assert.Equal(t,
cmd.Args,
[]string{"revive", "-formatter", "ndjson", "-config", configFile.Name(), "foo.go", "bar.go"},
)
}