From fef0b9d6274043dcc7b62c475973696b5a108c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20B=C3=A4ck?= Date: Thu, 2 Jan 2020 21:43:33 +0100 Subject: [PATCH] Enable prealloc checker and fix existing violations --- .golangci.yml | 1 + logstash-filter-verifier.go | 2 +- testcase/discover.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9ae5609..48f2589 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,6 +9,7 @@ linters: - gosimple - ineffassign - misspell + - prealloc - staticcheck - structcheck - typecheck diff --git a/logstash-filter-verifier.go b/logstash-filter-verifier.go index bdae7c6..36b0139 100644 --- a/logstash-filter-verifier.go +++ b/logstash-filter-verifier.go @@ -162,7 +162,7 @@ func runTests(inv *logstash.Invocation, tests []testcase.TestCaseSet, diffComman // the actual events against the expected set. Returns an error if // at least one test case fails or if there's a problem running the tests. func runParallelTests(inv *logstash.Invocation, tests []testcase.TestCaseSet, diffCommand []string, keptEnvVars []string) error { - var testStreams []*logstash.TestStream + testStreams := make([]*logstash.TestStream, 0, len(tests)) badCodecs := map[string]string{ "json": "json_lines", diff --git a/testcase/discover.go b/testcase/discover.go index a356038..d27a4d1 100644 --- a/testcase/discover.go +++ b/testcase/discover.go @@ -31,7 +31,7 @@ func discoverTestDirectory(path string) ([]TestCaseSet, error) { if err != nil { return nil, fmt.Errorf("Error discovering test case files: %s", err) } - var result []TestCaseSet + result := make([]TestCaseSet, 0, len(files)) for _, f := range files { if f.IsDir() || (!strings.HasSuffix(f.Name(), ".json") && !strings.HasSuffix(f.Name(), ".yaml") && !strings.HasSuffix(f.Name(), ".yml")) { continue