-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetTools_test.go
144 lines (137 loc) · 3.35 KB
/
getTools_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package tools
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFilterToolsByConfigUsage(t *testing.T) {
tests := []struct {
name string
inputTools []Tool
expectedCount int
expectedTools []string
}{
{
name: "tools with UsesConfigFile=true should be filtered out",
inputTools: []Tool{
{
Uuid: "eslint-uuid",
Name: "eslint",
Settings: struct {
Enabled bool `json:"isEnabled"`
UsesConfigFile bool `json:"hasConfigurationFile"`
}{
Enabled: true,
UsesConfigFile: true,
},
},
{
Uuid: "trivy-uuid",
Name: "trivy",
Settings: struct {
Enabled bool `json:"isEnabled"`
UsesConfigFile bool `json:"hasConfigurationFile"`
}{
Enabled: true,
UsesConfigFile: false,
},
},
{
Uuid: "pylint-uuid",
Name: "pylint",
Settings: struct {
Enabled bool `json:"isEnabled"`
UsesConfigFile bool `json:"hasConfigurationFile"`
}{
Enabled: true,
UsesConfigFile: false,
},
},
},
expectedCount: 2,
expectedTools: []string{"trivy", "pylint"},
},
{
name: "all tools using config should be filtered out",
inputTools: []Tool{
{
Uuid: "eslint-uuid",
Name: "eslint",
Settings: struct {
Enabled bool `json:"isEnabled"`
UsesConfigFile bool `json:"hasConfigurationFile"`
}{
Enabled: true,
UsesConfigFile: true,
},
},
{
Uuid: "trivy-uuid",
Name: "trivy",
Settings: struct {
Enabled bool `json:"isEnabled"`
UsesConfigFile bool `json:"hasConfigurationFile"`
}{
Enabled: true,
UsesConfigFile: true,
},
},
},
expectedCount: 0,
expectedTools: []string{},
},
{
name: "no tools using config should all pass through",
inputTools: []Tool{
{
Uuid: "eslint-uuid",
Name: "eslint",
Settings: struct {
Enabled bool `json:"isEnabled"`
UsesConfigFile bool `json:"hasConfigurationFile"`
}{
Enabled: true,
UsesConfigFile: false,
},
},
{
Uuid: "pylint-uuid",
Name: "pylint",
Settings: struct {
Enabled bool `json:"isEnabled"`
UsesConfigFile bool `json:"hasConfigurationFile"`
}{
Enabled: true,
UsesConfigFile: false,
},
},
},
expectedCount: 2,
expectedTools: []string{"eslint", "pylint"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Use the actual function being tested
result := FilterToolsByConfigUsage(tt.inputTools)
// Verify the count matches
assert.Equal(t, tt.expectedCount, len(result),
"Expected %d tools after filtering, got %d", tt.expectedCount, len(result))
// Verify each expected tool is in the result
for _, expectedTool := range tt.expectedTools {
found := false
for _, tool := range result {
if tool.Name == expectedTool {
found = true
break
}
}
assert.True(t, found, "Expected tool %s not found in filtered results", expectedTool)
}
// Verify no tools with UsesConfigFile=true are in the result
for _, tool := range result {
assert.False(t, tool.Settings.UsesConfigFile,
"Tool %s with UsesConfigFile=true should not be in filtered results", tool.Name)
}
})
}
}