-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathanalyzer_test.go
More file actions
110 lines (98 loc) · 2.54 KB
/
analyzer_test.go
File metadata and controls
110 lines (98 loc) · 2.54 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package gometalint
import (
"testing"
types "github.com/gogo/protobuf/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
log "gopkg.in/src-d/go-log.v1"
"gopkg.in/src-d/lookout-sdk.v0/pb"
)
var logger = log.New(nil)
func TestArgsEmpty(t *testing.T) {
require := require.New(t)
inputs := []types.Struct{
types.Struct{},
*pb.ToStruct(map[string]interface{}{
"linters": []map[string]interface{}{},
}),
*pb.ToStruct(map[string]interface{}{
"linters": []map[string]interface{}{
{
"name": "unknown",
"maxLen": 120,
},
},
}),
*pb.ToStruct(map[string]interface{}{
"linters": []map[string]interface{}{
{
"name": "lll",
},
},
}),
*pb.ToStruct(map[string]interface{}{
"linters": []map[string]interface{}{
{
"name": "lll",
"maxLen": "not a number",
},
},
}),
*pb.ToStruct(map[string]interface{}{
"linters": []map[string]interface{}{
{
"name": "lll",
"maxLen": 120.1,
},
},
}),
}
a := Analyzer{}
for i, input := range inputs {
require.Len(a.linterArguments(logger, input), 0, "test case %d; input: %+v", i, input)
}
}
func TestArgsCorrect(t *testing.T) {
a := Analyzer{}
require.Equal(t, []string{"--line-length=120"}, a.linterArguments(logger, *pb.ToStruct(map[string]interface{}{
"linters": []map[string]interface{}{
{
"name": "lll",
"maxLen": "120",
},
},
})))
require.Equal(t, []string{"--line-length=120"}, a.linterArguments(logger, *pb.ToStruct(map[string]interface{}{
"linters": []map[string]interface{}{
{
"name": "lll",
"maxLen": 120,
},
},
})))
}
var pathTests = []struct {
in string
out string
}{
{"a/b.go", "/tmp/a___.___b.go"},
{"tmp/a/b.go", "/tmp/tmp___.___a___.___b.go"},
{"a/b/c/d/e.go", "/tmp/a___.___b___.___c___.___d___.___e.go"},
}
func TestPathTransformations(t *testing.T) {
for _, tt := range pathTests {
t.Run(tt.in, func(t *testing.T) {
assert.Equal(t, tt.out, flattenPath(tt.in, "/tmp"))
assert.Equal(t, tt.in, revertOriginalPath(tt.out, "/tmp"))
})
}
}
func TestPathInTextTransformations(t *testing.T) {
tmp := "/var/folders/rx/z9zyr71d70x92zwbn3rrjx4c0000gn/T/gometalint584398570"
text := "duplicate of /var/folders/rx/z9zyr71d70x92zwbn3rrjx4c0000gn/T/gometalint584398570/provider___.___github___.___poster_test.go:549-554 (dupl)"
expectedText := "duplicate of provider/github/poster_test.go:549-554 (dupl)"
newText := revertOriginalPathIn(text, tmp)
if newText != expectedText {
t.Fatalf("got %q, want %q", newText, expectedText)
}
}