lint (copyloopvar)

This commit is contained in:
marco 2024-04-25 15:21:00 +02:00
parent 2abc078e53
commit 80d02006a7
31 changed files with 0 additions and 80 deletions

View file

@ -178,7 +178,6 @@ wowo: ajsajasjas
}
for _, tc := range tests {
tc := tc
t.Run(tc.TestName, func(t *testing.T) {
common := configuration.DataSourceCommonCfg{}
yaml.Unmarshal([]byte(tc.String), &common)
@ -281,7 +280,6 @@ func TestLoadAcquisitionFromFile(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.TestName, func(t *testing.T) {
dss, err := LoadAcquisitionFromFile(&tc.Config, nil)
cstest.RequireErrorContains(t, err, tc.ExpectedError)
@ -548,7 +546,6 @@ func TestConfigureByDSN(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.dsn, func(t *testing.T) {
srcs, err := LoadAcquisitionFromDSN(tc.dsn, map[string]string{"type": "test_label"}, "")
cstest.RequireErrorContains(t, err, tc.ExpectedError)

View file

@ -253,7 +253,6 @@ func (w *AppsecSource) StreamingAcquisition(out chan types.Event, t *tomb.Tomb)
w.logger.Infof("%d appsec runner to start", len(w.AppsecRunners))
for _, runner := range w.AppsecRunners {
runner := runner
runner.outChan = out
t.Go(func() error {
defer trace.CatchPanic("crowdsec/acquis/appsec/live/runner")

View file

@ -422,7 +422,6 @@ stream_name: test_stream`),
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
dbgLogger := log.New().WithField("test", tc.name)
dbgLogger.Logger.SetLevel(log.DebugLevel)
@ -555,7 +554,6 @@ stream_name: test_stream`),
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
dbgLogger := log.New().WithField("test", tc.name)
dbgLogger.Logger.SetLevel(log.DebugLevel)
@ -620,7 +618,6 @@ func TestConfigureByDSN(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
dbgLogger := log.New().WithField("test", tc.name)
dbgLogger.Logger.SetLevel(log.DebugLevel)
@ -742,7 +739,6 @@ func TestOneShotAcquisition(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
dbgLogger := log.New().WithField("test", tc.name)
dbgLogger.Logger.SetLevel(log.DebugLevel)

View file

@ -54,7 +54,6 @@ exclude_regexps: ["as[a-$d"]`,
})
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
f := fileacquisition.FileSource{}
err := f.Configure([]byte(tc.config), subLogger, configuration.METRICS_NONE)
@ -96,7 +95,6 @@ func TestConfigureDSN(t *testing.T) {
})
for _, tc := range tests {
tc := tc
t.Run(tc.dsn, func(t *testing.T) {
f := fileacquisition.FileSource{}
err := f.ConfigureByDSN(tc.dsn, map[string]string{"type": "testtype"}, subLogger, "")
@ -206,7 +204,6 @@ filename: test_files/test_delete.log`,
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
logger, hook := test.NewNullLogger()
logger.SetLevel(tc.logLevel)
@ -367,7 +364,6 @@ force_inotify: true`, testPattern),
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
logger, hook := test.NewNullLogger()
logger.SetLevel(tc.logLevel)

View file

@ -163,7 +163,6 @@ func TestStreamingAcquisition(t *testing.T) {
}
for _, ts := range tests {
ts := ts
t.Run(ts.name, func(t *testing.T) {
k := KafkaSource{}
err := k.Configure([]byte(`
@ -233,7 +232,6 @@ func TestStreamingAcquisitionWithSSL(t *testing.T) {
}
for _, ts := range tests {
ts := ts
t.Run(ts.name, func(t *testing.T) {
k := KafkaSource{}
err := k.Configure([]byte(`

View file

@ -22,7 +22,6 @@ func TestPri(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.input, func(t *testing.T) {
r := &RFC3164{}
r.buf = []byte(test.input)
@ -64,7 +63,6 @@ func TestTimestamp(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.input, func(t *testing.T) {
opts := []RFC3164Option{}
if test.currentYear {
@ -118,7 +116,6 @@ func TestHostname(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.input, func(t *testing.T) {
opts := []RFC3164Option{}
if test.strictHostname {
@ -163,7 +160,6 @@ func TestTag(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.input, func(t *testing.T) {
r := &RFC3164{}
r.buf = []byte(test.input)
@ -207,7 +203,6 @@ func TestMessage(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.input, func(t *testing.T) {
r := &RFC3164{}
r.buf = []byte(test.input)
@ -329,7 +324,6 @@ func TestParse(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.input, func(t *testing.T) {
r := NewRFC3164Parser(test.opts...)
err := r.Parse([]byte(test.input))

View file

@ -51,7 +51,6 @@ func BenchmarkParse(b *testing.B) {
}
var err error
for _, test := range tests {
test := test
b.Run(string(test.input), func(b *testing.B) {
for i := 0; i < b.N; i++ {
r := NewRFC3164Parser(test.opts...)

View file

@ -25,7 +25,6 @@ func TestPri(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.input, func(t *testing.T) {
r := &RFC5424{}
r.buf = []byte(test.input)
@ -61,7 +60,6 @@ func TestHostname(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.input, func(t *testing.T) {
opts := []RFC5424Option{}
if test.strictHostname {
@ -200,7 +198,6 @@ func TestParse(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
r := NewRFC5424Parser(test.opts...)
err := r.Parse([]byte(test.input))

View file

@ -92,7 +92,6 @@ func BenchmarkParse(b *testing.B) {
}
var err error
for _, test := range tests {
test := test
b.Run(test.label, func(b *testing.B) {
for i := 0; i < b.N; i++ {
r := NewRFC5424Parser()

View file

@ -132,7 +132,6 @@ listen_addr: 127.0.0.1`,
}
for _, ts := range tests {
ts := ts
t.Run(ts.name, func(t *testing.T) {
subLogger := log.WithFields(log.Fields{
"type": "syslog",

View file

@ -459,7 +459,6 @@ func TestDecisionsStreamOpts_addQueryParamsToURL(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
o := &DecisionsStreamOpts{
Startup: tt.fields.Startup,

View file

@ -65,7 +65,6 @@ func TestAPICSendMetrics(t *testing.T) {
defer httpmock.Deactivate()
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
url, err := url.ParseRequestURI("http://api.crowdsec.net/")
require.NoError(t, err)

View file

@ -162,7 +162,6 @@ func TestAPICFetchScenariosListFromDB(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
api := getAPIC(t)
for machineID, scenarios := range tc.machineIDsWithScenarios {
@ -229,7 +228,6 @@ func TestNewAPIC(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
setConfig()
httpmock.Activate()
@ -348,7 +346,6 @@ func TestAPICGetMetrics(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
apiClient := getAPIC(t)
cleanUp(apiClient)
@ -455,7 +452,6 @@ func TestCreateAlertsForDecision(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
if got := createAlertsForDecisions(tc.args.decisions); !reflect.DeepEqual(got, tc.want) {
t.Errorf("createAlertsForDecisions() = %v, want %v", got, tc.want)
@ -535,7 +531,6 @@ func TestFillAlertsWithDecisions(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
addCounters, _ := makeAddAndDeleteCounters()
if got := fillAlertsWithDecisions(tc.args.alerts, tc.args.decisions, addCounters); !reflect.DeepEqual(got, tc.want) {
@ -1092,7 +1087,6 @@ func TestAPICPush(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
api := getAPIC(t)
api.pushInterval = time.Millisecond
@ -1152,7 +1146,6 @@ func TestAPICPull(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
api = getAPIC(t)
api.pullInterval = time.Millisecond
@ -1279,7 +1272,6 @@ func TestShouldShareAlert(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
ret := shouldShareAlert(tc.alert, tc.consoleConfig)
assert.Equal(t, tc.expectedRet, ret)

View file

@ -64,7 +64,6 @@ func TestLoadLocalApiClientCfg(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.input.Load()
cstest.RequireErrorContains(t, err, tc.expectedErr)
@ -122,7 +121,6 @@ func TestLoadOnlineApiClientCfg(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.input.Load()
cstest.RequireErrorContains(t, err, tc.expectedErr)
@ -245,7 +243,6 @@ func TestLoadAPIServer(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.input.LoadAPIServer(false)
cstest.RequireErrorContains(t, err, tc.expectedErr)
@ -309,7 +306,6 @@ func TestParseCapiWhitelists(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
wl, err := parseCapiWhitelists(strings.NewReader(tc.input))
cstest.RequireErrorContains(t, err, tc.expectedErr)

View file

@ -32,7 +32,6 @@ func TestNewCrowdSecConfig(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
result := &Config{}
assert.Equal(t, tc.expected, result)

View file

@ -181,7 +181,6 @@ func TestLoadCrowdsec(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.input.LoadCrowdsec()
cstest.RequireErrorContains(t, err, tc.expectedErr)

View file

@ -39,7 +39,6 @@ func TestLoadCSCLI(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.input.loadCSCLI()
cstest.RequireErrorContains(t, err, tc.expectedErr)

View file

@ -46,7 +46,6 @@ func TestLoadDBConfig(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.input.LoadDBConfig(false)
cstest.RequireErrorContains(t, err, tc.expectedErr)

View file

@ -35,7 +35,6 @@ func TestLoadHub(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.input.loadHub()
cstest.RequireErrorContains(t, err, tc.expectedErr)

View file

@ -76,7 +76,6 @@ func TestSimulationLoading(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.input.LoadSimulation()
cstest.RequireErrorContains(t, err, tc.expectedErr)
@ -124,7 +123,6 @@ func TestIsSimulated(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
isSimulated := tc.SimulationConfig.IsSimulated(tc.Input)
require.Equal(t, tc.expected, isSimulated)

View file

@ -129,7 +129,6 @@ func (s *PluginSuite) TestBrokerInit() {
}
for _, tc := range tests {
tc := tc
s.Run(tc.name, func() {
t := s.T()
if tc.action != nil {

View file

@ -47,7 +47,6 @@ func TestListFilesAtPath(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
got, err := listFilesAtPath(tc.path)
cstest.RequireErrorContains(t, err, tc.expectedErr)

View file

@ -37,7 +37,6 @@ func TestGetPluginNameAndTypeFromPath(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
got, got1, err := getPluginTypeAndSubtypeFromPath(tc.path)
cstest.RequireErrorContains(t, err, tc.expectedErr)

View file

@ -102,7 +102,6 @@ func TestNewProfile(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
profilesCfg := []*csconfig.ProfileCfg{
test.profileCfg,
@ -196,7 +195,6 @@ func TestEvaluateProfile(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
profilesCfg := []*csconfig.ProfileCfg{
tt.args.profileCfg,

View file

@ -1150,7 +1150,6 @@ func TestParseUnixTime(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
output, err := ParseUnixTime(tc.value)
cstest.RequireErrorContains(t, err, tc.expectedErr)
@ -1252,7 +1251,6 @@ func TestIsIp(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
vm, err := expr.Compile(tc.expr, GetExprOptions(map[string]interface{}{"value": tc.value})...)
if tc.expectedBuildErr {
@ -1304,7 +1302,6 @@ func TestToString(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
vm, err := expr.Compile(tc.expr, GetExprOptions(map[string]interface{}{"value": tc.value})...)
require.NoError(t, err)
@ -1351,7 +1348,6 @@ func TestB64Decode(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
vm, err := expr.Compile(tc.expr, GetExprOptions(map[string]interface{}{"value": tc.value})...)
if tc.expectedBuildErr {
@ -1421,7 +1417,6 @@ func TestParseKv(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
outMap := make(map[string]interface{})
env := map[string]interface{}{

View file

@ -161,7 +161,6 @@ func TestJsonExtractSlice(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
env := map[string]interface{}{
"blob": test.jsonBlob,
@ -217,7 +216,6 @@ func TestJsonExtractObject(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
env := map[string]interface{}{
"blob": test.jsonBlob,

View file

@ -50,8 +50,6 @@ func TestRegisterFeature(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run("", func(t *testing.T) {
fr := fflag.FeatureRegister{EnvPrefix: "FFLAG_TEST_"}
err := fr.RegisterFeature(&tc.feature)
@ -112,7 +110,6 @@ func TestGetFeature(t *testing.T) {
fr := setUp(t)
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
_, err := fr.GetFeature(tc.feature)
cstest.RequireErrorMessage(t, err, tc.expectedErr)
@ -145,7 +142,6 @@ func TestIsEnabled(t *testing.T) {
fr := setUp(t)
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
feat, err := fr.GetFeature(tc.feature)
require.NoError(t, err)
@ -204,7 +200,6 @@ func TestFeatureSet(t *testing.T) {
fr := setUp(t)
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
feat, err := fr.GetFeature(tc.feature)
cstest.RequireErrorMessage(t, err, tc.expectedGetErr)
@ -284,7 +279,6 @@ func TestSetFromEnv(t *testing.T) {
fr := setUp(t)
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
logger, hook := logtest.NewNullLogger()
logger.SetLevel(logrus.DebugLevel)
@ -344,7 +338,6 @@ func TestSetFromYaml(t *testing.T) {
fr := setUp(t)
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
logger, hook := logtest.NewNullLogger()
logger.SetLevel(logrus.DebugLevel)

View file

@ -46,7 +46,6 @@ func TestDateParse(t *testing.T) {
"test": "test",
})
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
strTime, err := ParseDate(tt.evt.StrTime, &tt.evt, nil, logger)
cstest.RequireErrorContains(t, err, tt.expectedErr)

View file

@ -62,7 +62,6 @@ func TestWhitelistCompile(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
node.Whitelist = tt.whitelist
_, err := node.CompileWLs()
@ -284,7 +283,6 @@ func TestWhitelistCheck(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
var err error
node.Whitelist = tt.whitelist

View file

@ -94,7 +94,6 @@ func TestPathExists(t *testing.T) {
}
for _, tc := range tests {
tc := tc
env := setup.NewExprEnvironment(setup.DetectOptions{}, setup.ExprOS{})
t.Run(tc.path, func(t *testing.T) {
@ -147,7 +146,6 @@ func TestVersionCheck(t *testing.T) {
}
for _, tc := range tests {
tc := tc
e := setup.ExprOS{RawVersion: tc.version}
t.Run(fmt.Sprintf("Check(%s,%s)", tc.version, tc.constraint), func(t *testing.T) {
@ -246,7 +244,6 @@ func TestListSupported(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
f := tempYAML(t, tc.yml)
@ -329,7 +326,6 @@ func TestApplyRules(t *testing.T) {
env := setup.ExprEnvironment{}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
svc := setup.Service{When: tc.rules}
@ -419,7 +415,6 @@ detect:
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
f := tempYAML(t, tc.config)
defer os.Remove(f.Name())
@ -513,7 +508,6 @@ detect:
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
f := tempYAML(t, tc.config)
defer os.Remove(f.Name())
@ -825,7 +819,6 @@ func TestDetectForcedOS(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
f := tempYAML(t, tc.config)
defer os.Remove(f.Name())
@ -1011,7 +1004,6 @@ func TestDetectDatasourceValidation(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
f := tempYAML(t, tc.config)
defer os.Remove(f.Name())

View file

@ -41,7 +41,6 @@ func TestSetParsed(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tt.evt.SetParsed(tt.key, tt.value)
assert.Equal(t, tt.value, tt.evt.Parsed[tt.key])
@ -82,7 +81,6 @@ func TestSetMeta(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tt.evt.SetMeta(tt.key, tt.value)
assert.Equal(t, tt.value, tt.evt.GetMeta(tt.key))
@ -152,7 +150,6 @@ func TestParseIPSources(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
ips := tt.evt.ParseIPSources()
assert.Equal(t, tt.expected, ips)