From 485eb883d54c9b2b1b5ff691ccef25cd606c2cc1 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Tue, 3 Sep 2024 15:36:57 +0200 Subject: [PATCH 1/2] update go to 1.22 Signed-off-by: Paul Holzinger --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e9efb6e85..343e86e59 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/containers/common // Warning: Ensure the "go" and "toolchain" versions match exactly to prevent unwanted auto-updates -go 1.21.0 +go 1.22.0 require ( github.com/BurntSushi/toml v1.4.0 From 1750dbd0c0c3e23bcf1f0b5d41a603d8aef1a472 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Tue, 3 Sep 2024 15:57:02 +0200 Subject: [PATCH 2/2] update golangci-lint to 1.60.3 Contains fixes for new linters, removed depracted and removed linters from the config. Most notably because we use go 1.22 now we can get rid of the copy for loop vars[1]. Also as of the go 1..2 we can use the new int range syntax in for loops the new intrange linter checks that. [1] https://go.dev/blog/loopvar-preview Signed-off-by: Paul Holzinger --- .github/workflows/validate.yml | 2 +- .golangci.yml | 16 +++------------- Makefile | 2 +- libimage/filters.go | 2 +- libimage/image_test.go | 4 ++-- libimage/search.go | 4 ++-- libnetwork/cni/config_test.go | 1 - libnetwork/cni/run.go | 2 -- libnetwork/etchosts/hosts_test.go | 4 ---- libnetwork/internal/util/ip_test.go | 2 +- libnetwork/internal/util/parse_test.go | 3 --- libnetwork/internal/util/util.go | 2 +- libnetwork/internal/util/util_test.go | 1 - libnetwork/internal/util/validate.go | 1 - libnetwork/netavark/config.go | 2 +- libnetwork/netavark/ipam_test.go | 2 +- libnetwork/resolvconf/resolv_test.go | 3 --- libnetwork/slirp4netns/slirp4netns.go | 2 +- libnetwork/util/filters_test.go | 1 - pkg/cgroups/systemd_linux.go | 2 +- pkg/config/default_linux.go | 4 ++-- pkg/filters/filters_test.go | 3 --- pkg/hooks/exec/runtimeconfigfilter.go | 1 - pkg/manifests/manifests_test.go | 6 +++--- pkg/netns/netns_linux.go | 2 +- pkg/report/camelcase/camelcase.go | 2 +- pkg/report/formatter_test.go | 1 - pkg/report/template.go | 2 +- pkg/report/template_test.go | 2 -- pkg/report/validate_test.go | 1 - pkg/report/writer_test.go | 1 - pkg/secrets/passdriver/passdriver_test.go | 3 --- pkg/secrets/shelldriver/shelldriver_test.go | 3 --- pkg/systemd/systemd_linux.go | 2 +- 34 files changed, 25 insertions(+), 66 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 4d3e81224..cafca5458 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -11,7 +11,7 @@ on: permissions: read-all env: - LINT_VERSION: v1.56.2 + LINT_VERSION: v1.60.3 jobs: codespell: diff --git a/.golangci.yml b/.golangci.yml index fe3a9f1d1..6bc3f36f2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -14,17 +14,6 @@ run: linters: enable-all: true disable: - # linters deprecated by upstreams ... - - interfacer - - varcheck - - deadcode - - scopelint - - maligned - - nosnakecase - - exhaustivestruct - - structcheck - - ifshort - - golint # linters explicitly disabled for the below mentioned reasons ... - funlen # too aggressive/wishful size/statement limit - gochecknoinits # too many hard to fix init() funcs across the code @@ -41,9 +30,8 @@ linters: - errname - errorlint - exhaustive - - exhaustivestruct - gochecknoglobals - - goerr113 + - err113 - gomnd - nolintlint - wrapcheck @@ -60,12 +48,14 @@ linters: - maintidx - ireturn - exhaustruct + - execinquery - gosec - godot - gocyclo - dogsled - tparallel - thelper + - mnd #way to many false positives - nilnil - nilerr - interfacebloat diff --git a/Makefile b/Makefile index dd776a596..f1cff8b46 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,7 @@ vendor: .PHONY: install.tools install.tools: build/golangci-lint .install.md2man -build/golangci-lint: VERSION=v1.56.2 +build/golangci-lint: VERSION=v1.60.3 build/golangci-lint: curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/$(VERSION)/install.sh | sh -s -- -b ./build $(VERSION) diff --git a/libimage/filters.go b/libimage/filters.go index acb1df9fd..aa11d54f5 100644 --- a/libimage/filters.go +++ b/libimage/filters.go @@ -34,7 +34,7 @@ func (i *Image) applyFilters(ctx context.Context, filters compiledFilters, tree // meantime, so do an extra check and make the // error non-fatal (see containers/podman/issues/12582). if errCorrupted := i.isCorrupted(ctx, ""); errCorrupted != nil { - logrus.Errorf(errCorrupted.Error()) + logrus.Error(errCorrupted.Error()) return false, nil } return false, err diff --git a/libimage/image_test.go b/libimage/image_test.go index d463794fc..0f5333418 100644 --- a/libimage/image_test.go +++ b/libimage/image_test.go @@ -311,7 +311,7 @@ func TestTagAndUntagParallel(t *testing.T) { // Test tag in parallel, the extra go routine is critical for the test do not remove that. wg.Add(tagCount) - for i := 0; i < tagCount; i++ { + for i := range tagCount { name := fmt.Sprintf("localhost/tag-%d:latest", i) names = append(names, name) go func(name string) { @@ -331,7 +331,7 @@ func TestTagAndUntagParallel(t *testing.T) { // Test untag in parallel wg.Add(tagCount) - for i := 0; i < tagCount; i++ { + for i := range tagCount { name := fmt.Sprintf("localhost/tag-%d:latest", i) names = append(names, name) go func(name string) { diff --git a/libimage/search.go b/libimage/search.go index b26ad80d2..6ab016b3b 100644 --- a/libimage/search.go +++ b/libimage/search.go @@ -215,7 +215,7 @@ func (r *Runtime) searchImageInRegistry(ctx context.Context, term, registry stri } paramsArr := []SearchResult{} - for i := 0; i < limit; i++ { + for i := range limit { // Check whether query matches filters if !(filterMatchesAutomatedFilter(&options.Filter, results[i]) && filterMatchesOfficialFilter(&options.Filter, results[i]) && filterMatchesStarFilter(&options.Filter, results[i])) { continue @@ -275,7 +275,7 @@ func searchRepositoryTags(ctx context.Context, sys *types.SystemContext, registr } } paramsArr := []SearchResult{} - for i := 0; i < limit; i++ { + for i := range limit { params := SearchResult{ Name: imageRef.DockerReference().Name(), Tag: tags[i], diff --git a/libnetwork/cni/config_test.go b/libnetwork/cni/config_test.go index a8a87b171..37e7bab76 100644 --- a/libnetwork/cni/config_test.go +++ b/libnetwork/cni/config_test.go @@ -520,7 +520,6 @@ var _ = Describe("Config", func() { }) for _, driver := range []string{"macvlan", "ipvlan"} { - driver := driver It(fmt.Sprintf("create %s config with none ipam driver", driver), func() { network := types.Network{ Driver: driver, diff --git a/libnetwork/cni/run.go b/libnetwork/cni/run.go index 337a27b8e..68a42945c 100644 --- a/libnetwork/cni/run.go +++ b/libnetwork/cni/run.go @@ -62,7 +62,6 @@ func (n *cniNetwork) Setup(namespacePath string, options types.SetupOptions) (ma } for name, netOpts := range options.Networks { - netOpts := netOpts network := n.networks[name] rt := getRuntimeConfig(namespacePath, options.ContainerName, options.ContainerID, name, ports, &netOpts) @@ -237,7 +236,6 @@ func (n *cniNetwork) teardown(namespacePath string, options types.TeardownOption var multiErr *multierror.Error teardown := func() error { for name, netOpts := range options.Networks { - netOpts := netOpts rt := getRuntimeConfig(namespacePath, options.ContainerName, options.ContainerID, name, ports, &netOpts) cniConfList, newRt, err := getCachedNetworkConfig(n.cniConf, name, rt) diff --git a/libnetwork/etchosts/hosts_test.go b/libnetwork/etchosts/hosts_test.go index 6654125df..277a1d026 100644 --- a/libnetwork/etchosts/hosts_test.go +++ b/libnetwork/etchosts/hosts_test.go @@ -290,7 +290,6 @@ func TestNew(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { baseHostFile := tt.baseFileName if !tt.noWriteBaseFile { @@ -364,7 +363,6 @@ func TestAdd(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { f, err := os.CreateTemp(t.TempDir(), "hosts") assert.NoErrorf(t, err, "failed to create base host file: %v", err) @@ -460,7 +458,6 @@ func TestAddIfExists(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { f, err := os.CreateTemp(t.TempDir(), "hosts") assert.NoErrorf(t, err, "failed to create base host file: %v", err) @@ -523,7 +520,6 @@ func TestRemove(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { f, err := os.CreateTemp(t.TempDir(), "hosts") assert.NoErrorf(t, err, "failed to create base host file: %v", err) diff --git a/libnetwork/internal/util/ip_test.go b/libnetwork/internal/util/ip_test.go index 94547cba3..527463f76 100644 --- a/libnetwork/internal/util/ip_test.go +++ b/libnetwork/internal/util/ip_test.go @@ -53,7 +53,7 @@ func TestNextSubnet(t *testing.T) { } func TestGetRandomIPv6Subnet(t *testing.T) { - for i := 0; i < 1000; i++ { + for i := range 1000 { t.Run(fmt.Sprintf("GetRandomIPv6Subnet %d", i), func(t *testing.T) { sub, err := getRandomIPv6Subnet() if err != nil { diff --git a/libnetwork/internal/util/parse_test.go b/libnetwork/internal/util/parse_test.go index 595b4bdd6..11b5b4f94 100644 --- a/libnetwork/internal/util/parse_test.go +++ b/libnetwork/internal/util/parse_test.go @@ -45,7 +45,6 @@ func TestParseMTU(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { got, err := ParseMTU(tt.args.mtuOption) if (err != nil) != tt.wantErr { @@ -113,7 +112,6 @@ func TestParseVlan(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { got, err := ParseVlan(tt.args.vlanOption) if (err != nil) != tt.wantErr { @@ -202,7 +200,6 @@ func TestParseIsolate(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { got, err := ParseIsolate(tt.args.isolateOption) if (err != nil) != tt.wantErr { diff --git a/libnetwork/internal/util/util.go b/libnetwork/internal/util/util.go index 96c21e76f..260e74d06 100644 --- a/libnetwork/internal/util/util.go +++ b/libnetwork/internal/util/util.go @@ -112,7 +112,7 @@ func GetFreeIPv4NetworkSubnet(usedNetworks []*net.IPNet, subnetPools []config.Su // GetFreeIPv6NetworkSubnet returns a unused ipv6 subnet func GetFreeIPv6NetworkSubnet(usedNetworks []*net.IPNet) (*types.Subnet, error) { // FIXME: Is 10000 fine as limit? We should prevent an endless loop. - for i := 0; i < 10000; i++ { + for range 10000 { // RFC4193: Choose the ipv6 subnet random and NOT sequentially. network, err := getRandomIPv6Subnet() if err != nil { diff --git a/libnetwork/internal/util/util_test.go b/libnetwork/internal/util/util_test.go index a428c2031..c7b4ade8e 100644 --- a/libnetwork/internal/util/util_test.go +++ b/libnetwork/internal/util/util_test.go @@ -101,7 +101,6 @@ func TestGetFreeIPv4NetworkSubnet(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { got, err := GetFreeIPv4NetworkSubnet(tt.args.usedNetworks, tt.args.subnetPools) if (err != nil) != tt.wantErr { diff --git a/libnetwork/internal/util/validate.go b/libnetwork/internal/util/validate.go index 55995440e..ddc778a5f 100644 --- a/libnetwork/internal/util/validate.go +++ b/libnetwork/internal/util/validate.go @@ -129,7 +129,6 @@ func ValidateSetupOptions(n NetUtil, namespacePath string, options types.SetupOp return errors.New("must specify at least one network") } for name, netOpts := range options.Networks { - netOpts := netOpts network, err := n.Network(name) if err != nil { return err diff --git a/libnetwork/netavark/config.go b/libnetwork/netavark/config.go index 842c7e312..8b43a787e 100644 --- a/libnetwork/netavark/config.go +++ b/libnetwork/netavark/config.go @@ -126,7 +126,7 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo // generate random network ID var i int - for i = 0; i < 1000; i++ { + for i = range 1000 { id := stringid.GenerateNonCryptoID() if _, err := n.getNetwork(id); err != nil { newNetwork.ID = id diff --git a/libnetwork/netavark/ipam_test.go b/libnetwork/netavark/ipam_test.go index 47677e9d5..cbe0f5beb 100644 --- a/libnetwork/netavark/ipam_test.go +++ b/libnetwork/netavark/ipam_test.go @@ -393,7 +393,7 @@ var _ = Describe("IPAM", func() { Expect(err).ToNot(HaveOccurred()) } - for i := 0; i < 30; i++ { + for i := range 30 { opts := types.NetworkOptions{ ContainerID: fmt.Sprintf("id-%d", i), Networks: map[string]types.PerNetworkOptions{ diff --git a/libnetwork/resolvconf/resolv_test.go b/libnetwork/resolvconf/resolv_test.go index 71df11111..07a975dc3 100644 --- a/libnetwork/resolvconf/resolv_test.go +++ b/libnetwork/resolvconf/resolv_test.go @@ -124,7 +124,6 @@ func TestNew(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { base := filepath.Join(t.TempDir(), "resolv.conf") target := filepath.Join(t.TempDir(), "new-resolv.conf") @@ -185,7 +184,6 @@ options edns0 }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { resolvPath := filepath.Join(t.TempDir(), "resolv.conf") err := os.WriteFile(resolvPath, []byte(tt.content), 0o644) @@ -228,7 +226,6 @@ options edns0 }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { resolvPath := filepath.Join(t.TempDir(), "resolv.conf") err := os.WriteFile(resolvPath, []byte(tt.content), 0o644) diff --git a/libnetwork/slirp4netns/slirp4netns.go b/libnetwork/slirp4netns/slirp4netns.go index 6f713431c..9721750ab 100644 --- a/libnetwork/slirp4netns/slirp4netns.go +++ b/libnetwork/slirp4netns/slirp4netns.go @@ -645,7 +645,7 @@ func setupRootlessPortMappingViaSlirp(ports []types.PortMapping, cmd *exec.Cmd, if hostIP == "" { hostIP = "0.0.0.0" } - for i := uint16(0); i < port.Range; i++ { + for i := range port.Range { if err := openSlirp4netnsPort(apiSocket, protocol, hostIP, port.HostPort+i, port.ContainerPort+i); err != nil { return err } diff --git a/libnetwork/util/filters_test.go b/libnetwork/util/filters_test.go index cb1e09986..442fbce42 100644 --- a/libnetwork/util/filters_test.go +++ b/libnetwork/util/filters_test.go @@ -35,7 +35,6 @@ func TestGenerateFilterFunc(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { for _, entry := range tt.args.keys { if _, err := createFilterFuncs(entry, tt.args.labels); err != nil { diff --git a/pkg/cgroups/systemd_linux.go b/pkg/cgroups/systemd_linux.go index ead630e75..b1529410f 100644 --- a/pkg/cgroups/systemd_linux.go +++ b/pkg/cgroups/systemd_linux.go @@ -23,7 +23,7 @@ func systemdCreate(resources *configs.Resources, path string, c *systemdDbus.Con slice = strings.TrimSuffix(slice, "/") var lastError error - for i := 0; i < 2; i++ { + for i := range 2 { properties := []systemdDbus.Property{ systemdDbus.PropDescription("cgroup " + name), systemdDbus.PropWants(slice), diff --git a/pkg/config/default_linux.go b/pkg/config/default_linux.go index 9e2ae4796..64a98384e 100644 --- a/pkg/config/default_linux.go +++ b/pkg/config/default_linux.go @@ -28,9 +28,9 @@ func getDefaultProcessLimits() []string { dat, err := os.ReadFile("/proc/sys/kernel/pid_max") if err == nil { val := strings.TrimSuffix(string(dat), "\n") - max, err := strconv.ParseUint(val, 10, 64) + maxLimit, err := strconv.ParseUint(val, 10, 64) if err == nil { - rlim = unix.Rlimit{Cur: max, Max: max} + rlim = unix.Rlimit{Cur: maxLimit, Max: maxLimit} } } defaultLimits := []string{} diff --git a/pkg/filters/filters_test.go b/pkg/filters/filters_test.go index 1dc5958ec..415b2c713 100644 --- a/pkg/filters/filters_test.go +++ b/pkg/filters/filters_test.go @@ -74,7 +74,6 @@ func TestMatchLabelFilters(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { if got := MatchLabelFilters(tt.args.filterValues, tt.args.labels); got != tt.want { t.Errorf("MatchLabelFilters() = %v, want %v", got, tt.want) @@ -148,7 +147,6 @@ func TestMatchNegatedLabelFilters(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { if got := MatchNegatedLabelFilters(tt.args.filterValues, tt.args.labels); got != tt.want { t.Errorf("MatchNegatedLabelFilters() = %v, want %v", got, tt.want) @@ -180,7 +178,6 @@ func TestComputeUntilTimestamp(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { _, err := ComputeUntilTimestamp(tt.args) if (err != nil) != tt.wantErr { diff --git a/pkg/hooks/exec/runtimeconfigfilter.go b/pkg/hooks/exec/runtimeconfigfilter.go index ac17ac64d..302711260 100644 --- a/pkg/hooks/exec/runtimeconfigfilter.go +++ b/pkg/hooks/exec/runtimeconfigfilter.go @@ -56,7 +56,6 @@ func RuntimeConfigFilterWithOptions(ctx context.Context, options RuntimeConfigFi return nil, err } for i, hook := range options.Hooks { - hook := hook var stdout bytes.Buffer hookErr, err = RunWithOptions(ctx, RunOptions{Hook: &hook, Dir: options.Dir, State: data, Stdout: &stdout, PostKillTimeout: options.PostKillTimeout}) if err != nil { diff --git a/pkg/manifests/manifests_test.go b/pkg/manifests/manifests_test.go index c5d3322a5..14659be1a 100644 --- a/pkg/manifests/manifests_test.go +++ b/pkg/manifests/manifests_test.go @@ -209,7 +209,7 @@ func testStringSlice(t *testing.T, values [][]string, set func(List, digest.Dige } } -func testMap(t *testing.T, values []map[string]string, set func(List, *digest.Digest, map[string]string) error, clear func(List, *digest.Digest) error, get func(List, *digest.Digest) (map[string]string, error)) { +func testMap(t *testing.T, values []map[string]string, set func(List, *digest.Digest, map[string]string) error, clearFunc func(List, *digest.Digest) error, get func(List, *digest.Digest) (map[string]string, error)) { bytes, err := os.ReadFile(ociFixture) if err != nil { t.Fatalf("error loading blob: %v", err) @@ -221,7 +221,7 @@ func testMap(t *testing.T, values []map[string]string, set func(List, *digest.Di instance := expectedInstance for _, instanceDigest := range []*digest.Digest{nil, &instance} { for _, testMap := range values { - if err = clear(list, instanceDigest); err != nil { + if err = clearFunc(list, instanceDigest); err != nil { t.Fatalf("error clearing %v: %v", testMap, err) } if err = set(list, instanceDigest, testMap); err != nil { @@ -247,7 +247,7 @@ func testMap(t *testing.T, values []map[string]string, set func(List, *digest.Di t.Fatalf("expected map value %q=%q, got %q", k, v, values[k]) } } - if err = clear(list, instanceDigest); err != nil { + if err = clearFunc(list, instanceDigest); err != nil { t.Fatalf("error clearing %v: %v", testMap, err) } values, err = get(list, instanceDigest) diff --git a/pkg/netns/netns_linux.go b/pkg/netns/netns_linux.go index bbcedc0f6..db35fd15a 100644 --- a/pkg/netns/netns_linux.go +++ b/pkg/netns/netns_linux.go @@ -60,7 +60,7 @@ func NewNSAtPath(nsPath string) (ns.NetNS, error) { // NewNS creates a new persistent (bind-mounted) network namespace and returns // an object representing that namespace, without switching to it. func NewNS() (ns.NetNS, error) { - for i := 0; i < 10000; i++ { + for range 10000 { b := make([]byte, 16) _, err := rand.Reader.Read(b) if err != nil { diff --git a/pkg/report/camelcase/camelcase.go b/pkg/report/camelcase/camelcase.go index 830482ff0..adafb1c26 100644 --- a/pkg/report/camelcase/camelcase.go +++ b/pkg/report/camelcase/camelcase.go @@ -73,7 +73,7 @@ func Split(src string) (entries []string) { } // handle upper case -> lower case sequences, e.g. // "PDFL", "oader" -> "PDF", "Loader" - for i := 0; i < len(runes)-1; i++ { + for i := range len(runes) - 1 { if unicode.IsUpper(runes[i][0]) && unicode.IsLower(runes[i+1][0]) { runes[i+1] = append([]rune{runes[i][len(runes[i])-1]}, runes[i+1]...) runes[i] = runes[i][:len(runes[i])-1] diff --git a/pkg/report/formatter_test.go b/pkg/report/formatter_test.go index 4c989a561..1eea0bfbb 100644 --- a/pkg/report/formatter_test.go +++ b/pkg/report/formatter_test.go @@ -88,7 +88,6 @@ func TestFormatter_ParseTable(t *testing.T) { } for loop, tc := range testCase { - tc := tc name := fmt.Sprintf("Loop#%d", loop) t.Run(name, func(t *testing.T) { buf := new(bytes.Buffer) diff --git a/pkg/report/template.go b/pkg/report/template.go index 0f7d5e5bf..607bb7ff2 100644 --- a/pkg/report/template.go +++ b/pkg/report/template.go @@ -101,7 +101,7 @@ func Headers(object any, overrides map[string]string) []map[string]string { // Column header will be field name upper-cased. headers := make(map[string]string, value.NumField()) - for i := 0; i < value.Type().NumField(); i++ { + for i := range value.Type().NumField() { field := value.Type().Field(i) // Recurse to find field names from promoted structs if field.Type.Kind() == reflect.Struct && field.Anonymous { diff --git a/pkg/report/template_test.go b/pkg/report/template_test.go index 01b775d0e..5cba5e140 100644 --- a/pkg/report/template_test.go +++ b/pkg/report/template_test.go @@ -56,7 +56,6 @@ func TestNormalizeFormat(t *testing.T) { } for _, tc := range testCase { - tc := tc t.Run(tc.input, func(t *testing.T) { t.Parallel() assert.Equal(t, tc.expected, NormalizeFormat(tc.input)) @@ -75,7 +74,6 @@ func TestTemplate_Parse(t *testing.T) { var buf bytes.Buffer for _, tc := range testCase { - tc := tc t.Run(tc, func(t *testing.T) { tmpl, e := NewTemplate("TestTemplate").Parse(tc) assert.NoError(t, e) diff --git a/pkg/report/validate_test.go b/pkg/report/validate_test.go index e8505f7e7..09c692011 100644 --- a/pkg/report/validate_test.go +++ b/pkg/report/validate_test.go @@ -33,7 +33,6 @@ func TestIsJSON(t *testing.T) { } for _, tc := range tests { - tc := tc label := "JSONFormat/" + strings.ReplaceAll(tc.input, " ", "_") t.Run(label, func(t *testing.T) { t.Parallel() diff --git a/pkg/report/writer_test.go b/pkg/report/writer_test.go index baef65e1a..f69179131 100644 --- a/pkg/report/writer_test.go +++ b/pkg/report/writer_test.go @@ -18,7 +18,6 @@ func TestNewWriter(t *testing.T) { var buf bytes.Buffer for _, tc := range testCases { - tc := tc t.Run(tc.input, func(t *testing.T) { w, err := NewWriter(&buf, 4, 8, 1, ':', 0) assert.NoError(t, err) diff --git a/pkg/secrets/passdriver/passdriver_test.go b/pkg/secrets/passdriver/passdriver_test.go index 86dffcc1f..32c7a5386 100644 --- a/pkg/secrets/passdriver/passdriver_test.go +++ b/pkg/secrets/passdriver/passdriver_test.go @@ -60,7 +60,6 @@ func TestStoreAndLookup(t *testing.T) { } for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { driver := setupDriver(t) err := driver.Store(tc.key, tc.value) @@ -113,7 +112,6 @@ func TestLookup(t *testing.T) { } for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { val, err := driver.Lookup(tc.key) if tc.expErr == nil { @@ -162,7 +160,6 @@ func TestDelete(t *testing.T) { } for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { err := driver.Delete(tc.key) if tc.expErr != nil { diff --git a/pkg/secrets/shelldriver/shelldriver_test.go b/pkg/secrets/shelldriver/shelldriver_test.go index 6c5f1468d..04c10c3ac 100644 --- a/pkg/secrets/shelldriver/shelldriver_test.go +++ b/pkg/secrets/shelldriver/shelldriver_test.go @@ -52,7 +52,6 @@ func TestStoreAndLookup(t *testing.T) { } for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { driver := setupDriver(t) err := driver.Store(tc.key, tc.value) @@ -105,7 +104,6 @@ func TestLookup(t *testing.T) { } for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { val, err := driver.Lookup(tc.key) if tc.expErr == nil { @@ -154,7 +152,6 @@ func TestDelete(t *testing.T) { } for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { err := driver.Delete(tc.key) if tc.expErr != nil { diff --git a/pkg/systemd/systemd_linux.go b/pkg/systemd/systemd_linux.go index c1d8ed72e..ea61ecaa1 100644 --- a/pkg/systemd/systemd_linux.go +++ b/pkg/systemd/systemd_linux.go @@ -74,7 +74,7 @@ func MoveRootlessNetnsSlirpProcessToUserSlice(pid int) error { func MovePauseProcessToScope(pausePidPath string) { var err error - for i := 0; i < 10; i++ { + for range 10 { randBytes := make([]byte, 4) _, err = rand.Read(randBytes) if err != nil {