@@ -1118,3 +1118,102 @@ func TestSkipDeprecatedGoChecks(t *testing.T) {
1118
1118
require .Len (t , results , 1 )
1119
1119
})
1120
1120
}
1121
+
1122
+ func TestSkipDir (t * testing.T ) {
1123
+ fs := testutil .CreateFS (t , map [string ]string {
1124
+ "deployments/main.tf" : `
1125
+ module "use_bad_configuration" {
1126
+ source = "../modules"
1127
+ }
1128
+
1129
+ module "use_bad_configuration_2" {
1130
+ source = "../modules/modules2"
1131
+ }
1132
+ ` ,
1133
+ "modules/misconfig.tf" : `data "aws_iam_policy_document" "bad" {
1134
+ statement {
1135
+ actions = [
1136
+ "apigateway:*",
1137
+ ]
1138
+
1139
+ resources = [
1140
+ "*",
1141
+ ]
1142
+ }
1143
+ }
1144
+
1145
+ resource "aws_iam_policy" "bad_configuration" {
1146
+ name_prefix = local.setup_role_name
1147
+ policy = data.aws_iam_policy_document.bad.json
1148
+ }
1149
+ ` ,
1150
+ "modules/modules2/misconfig.tf" : `data "aws_iam_policy_document" "bad" {
1151
+ statement {
1152
+ actions = [
1153
+ "apigateway:*",
1154
+ ]
1155
+
1156
+ resources = [
1157
+ "*",
1158
+ ]
1159
+ }
1160
+ }
1161
+
1162
+ resource "aws_iam_policy" "bad_configuration" {
1163
+ name_prefix = local.setup_role_name
1164
+ policy = data.aws_iam_policy_document.bad.json
1165
+ }
1166
+ ` ,
1167
+ })
1168
+
1169
+ t .Run ("use skip-dir option" , func (t * testing.T ) {
1170
+ scanner := New (
1171
+ options .ScannerWithIncludeDeprecatedChecks (true ),
1172
+ ScannerWithSkipDirs ([]string {"**/modules/**" }),
1173
+ ScannerWithAllDirectories (true ),
1174
+ )
1175
+
1176
+ results , err := scanner .ScanFS (context .TODO (), fs , "deployments" )
1177
+ require .NoError (t , err )
1178
+
1179
+ assert .Empty (t , results )
1180
+ })
1181
+
1182
+ t .Run ("use skip-files option" , func (t * testing.T ) {
1183
+ scanner := New (
1184
+ options .ScannerWithIncludeDeprecatedChecks (true ),
1185
+ ScannerWithSkipFiles ([]string {"**/modules/**/*.tf" }),
1186
+ ScannerWithAllDirectories (true ),
1187
+ )
1188
+
1189
+ results , err := scanner .ScanFS (context .TODO (), fs , "deployments" )
1190
+ require .NoError (t , err )
1191
+
1192
+ assert .Empty (t , results )
1193
+ })
1194
+
1195
+ t .Run ("non existing value for skip-files option" , func (t * testing.T ) {
1196
+ scanner := New (
1197
+ options .ScannerWithIncludeDeprecatedChecks (true ),
1198
+ ScannerWithSkipFiles ([]string {"foo/bar*.tf" }),
1199
+ ScannerWithAllDirectories (true ),
1200
+ )
1201
+
1202
+ results , err := scanner .ScanFS (context .TODO (), fs , "deployments" )
1203
+ require .NoError (t , err )
1204
+
1205
+ assert .Len (t , results , 4 )
1206
+ })
1207
+
1208
+ t .Run ("empty skip-files option" , func (t * testing.T ) {
1209
+ scanner := New (
1210
+ options .ScannerWithIncludeDeprecatedChecks (true ),
1211
+ ScannerWithAllDirectories (true ),
1212
+ )
1213
+
1214
+ results , err := scanner .ScanFS (context .TODO (), fs , "deployments" )
1215
+ require .NoError (t , err )
1216
+
1217
+ assert .Len (t , results , 4 )
1218
+ })
1219
+ }
0 commit comments