-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfiguration_test.go
93 lines (79 loc) · 1.94 KB
/
configuration_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
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
package main
import (
"fmt"
"testing"
codacy "github.com/codacy/codacy-engine-golang-seed/v6"
"github.com/stretchr/testify/assert"
)
func patternStruct() (codacy.Pattern, string) {
return codacy.Pattern{
ID: "testing",
Parameters: []codacy.PatternParameter{
{
Name: "param1",
Value: "value1",
},
{
Name: "param2",
Value: "value2",
}},
Category: "UnusedCode",
Level: "Info",
}, `
[rule]
[rule.testing]
[[rule.testing.arguments]]
param1 = "value1"
param2 = "value2"
`
}
func patternUnnamedStruct() (codacy.Pattern, string) {
return codacy.Pattern{
ID: "var-naming",
Parameters: []codacy.PatternParameter{
{
Name: unnamedParamName,
Value: "value1",
},
{
Name: "param2",
Value: "value2",
}},
Category: "UnusedCode",
Level: "Info",
}, `
[rule.testingUnnamed]
arguments = ["value1"]
`
}
func patternRawStruct() (codacy.Pattern, string) {
return codacy.Pattern{
ID: "var-naming",
Category: "UnusedCode",
Level: "Info",
}, `
[rule.var-naming]
`
}
func TestPatternsToToml(t *testing.T) {
pattern, _ := patternStruct()
reviveConfigMap := patternsToReviveConfigMap([]codacy.Pattern{pattern})
value, ok := reviveConfigMap["rule"].(map[string]interface{})
if !ok {
assert.Fail(t, "Revive config map does not have the expected structure")
}
assert.NotNil(t, value[pattern.ID], "Expected toml: %s to exist", pattern.ID)
}
func TestConfigurationContentGeneration(t *testing.T) {
pattern, patternTomlExpected := patternStruct()
unnamedParamPattern, unnamedParamTomlExpected := patternRawStruct()
patterns := []codacy.Pattern{
pattern,
unnamedParamPattern,
}
fmt.Println(patterns)
configContent := generateToolConfigurationContent(patterns)
fmt.Println(configContent)
expectedContent := fmt.Sprintf("%s%s", patternTomlExpected, unnamedParamTomlExpected)
assert.Equal(t, expectedContent, configContent)
}