From 130861be1b6fdfdc34a8eb47be5cacc6cd20d4b1 Mon Sep 17 00:00:00 2001 From: Adam Hughes <9903835+tri-adam@users.noreply.github.com> Date: Thu, 21 Mar 2024 21:30:27 +0000 Subject: [PATCH 1/2] chore: bump golangci-lint to v1.57 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ef4d74d..212e81b1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,7 +9,7 @@ executors: - image: node:20-slim golangci-lint: docker: - - image: golangci/golangci-lint:v1.56 + - image: golangci/golangci-lint:v1.57 golang-previous: docker: - image: golang:1.21 From 60d5791308d75d73e991d4c29eb9e937fe56bebd Mon Sep 17 00:00:00 2001 From: Adam Hughes <9903835+tri-adam@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:54:24 +0000 Subject: [PATCH 2/2] lint: add new linters Enable copyloopvar and intrange linters. They won't activate until the module adopts Go 1.22, but run cleanly at the moment. --- .golangci.yml | 2 ++ internal/app/siftool/info_test.go | 4 +--- pkg/integrity/clearsign_test.go | 4 +--- pkg/integrity/digest_test.go | 5 +---- pkg/integrity/dsse_test.go | 4 +--- pkg/integrity/metadata_test.go | 5 +---- pkg/integrity/sign_test.go | 6 ------ pkg/integrity/verify_test.go | 10 ---------- pkg/sif/descriptor_test.go | 3 +-- pkg/sif/load_test.go | 6 +----- pkg/sif/sif_test.go | 3 +-- 11 files changed, 10 insertions(+), 42 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9cd18fb5..4e9ba72a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,6 +6,7 @@ linters: - bodyclose - containedctx - contextcheck + - copyloopvar - decorder - dogsled - dupl @@ -31,6 +32,7 @@ linters: - grouper - ineffassign - interfacebloat + - intrange - ireturn - lll - maintidx diff --git a/internal/app/siftool/info_test.go b/internal/app/siftool/info_test.go index e0d75a5d..1ec9c737 100644 --- a/internal/app/siftool/info_test.go +++ b/internal/app/siftool/info_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2023, Sylabs Inc. All rights reserved. +// Copyright (c) 2021-2024, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the // LICENSE file distributed with the sources of this project regarding your // rights to use or distribute this software. @@ -66,8 +66,6 @@ func Test_readableSize(t *testing.T) { }, } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { if got, want := readableSize(tt.size), tt.want; got != want { t.Errorf("got %v, want %v", got, want) diff --git a/pkg/integrity/clearsign_test.go b/pkg/integrity/clearsign_test.go index 8810bd4e..0de5e321 100644 --- a/pkg/integrity/clearsign_test.go +++ b/pkg/integrity/clearsign_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2023, Sylabs Inc. All rights reserved. +// Copyright (c) 2020-2024, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file // distributed with the sources of this project regarding your rights to use or distribute this // software. @@ -51,7 +51,6 @@ func Test_clearsignEncoder_signMessage(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { b := bytes.Buffer{} @@ -170,7 +169,6 @@ func Test_clearsignDecoder_verifyMessage(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { b := bytes.Buffer{} diff --git a/pkg/integrity/digest_test.go b/pkg/integrity/digest_test.go index 128e10c1..18af1d49 100644 --- a/pkg/integrity/digest_test.go +++ b/pkg/integrity/digest_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022, Sylabs Inc. All rights reserved. +// Copyright (c) 2020-2024, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file // distributed with the sources of this project regarding your rights to use or distribute this // software. @@ -90,7 +90,6 @@ func TestNewLegacyDigest(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { d, err := newLegacyDigest(tt.ht, []byte(tt.text)) if got, want := err, tt.wantError; !errors.Is(got, want) { @@ -156,7 +155,6 @@ func TestDigest_MarshalJSON(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { value, err := hex.DecodeString(tt.value) if err != nil { @@ -261,7 +259,6 @@ func TestDigest_UnmarshalJSON(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { var d digest diff --git a/pkg/integrity/dsse_test.go b/pkg/integrity/dsse_test.go index 30dd158f..fe61f364 100644 --- a/pkg/integrity/dsse_test.go +++ b/pkg/integrity/dsse_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022-2023, Sylabs Inc. All rights reserved. +// Copyright (c) 2022-2024, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file // distributed with the sources of this project regarding your rights to use or distribute this // software. @@ -78,7 +78,6 @@ func Test_dsseEncoder_signMessage(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { b := bytes.Buffer{} @@ -319,7 +318,6 @@ func Test_dsseDecoder_verifyMessage(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { b := bytes.Buffer{} diff --git a/pkg/integrity/metadata_test.go b/pkg/integrity/metadata_test.go index b78ec2f8..80281ee5 100644 --- a/pkg/integrity/metadata_test.go +++ b/pkg/integrity/metadata_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022, Sylabs Inc. All rights reserved. +// Copyright (c) 2020-2024, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file // distributed with the sources of this project regarding your rights to use or distribute this // software. @@ -46,7 +46,6 @@ func TestGetHeaderMetadata(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { md, err := getHeaderMetadata(tt.header, tt.hash) if got, want := err, tt.wantErr; !errors.Is(got, want) { @@ -102,7 +101,6 @@ func TestGetObjectMetadata(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { md, err := getObjectMetadata(tt.relativeID, tt.descr, tt.data, tt.hash) if got, want := err, tt.wantErr; !errors.Is(got, want) { @@ -155,7 +153,6 @@ func TestGetImageMetadata(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { md, err := getImageMetadata(f, tt.minID, tt.ods, tt.hash) if got, want := err, tt.wantErr; !errors.Is(got, want) { diff --git a/pkg/integrity/sign_test.go b/pkg/integrity/sign_test.go index 821f61ea..cb878aee 100644 --- a/pkg/integrity/sign_test.go +++ b/pkg/integrity/sign_test.go @@ -68,7 +68,6 @@ func TestOptSignGroupObjects(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { gs := groupSigner{f: twoGroupImage, id: tt.groupID} @@ -195,7 +194,6 @@ func TestNewGroupSigner(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { en := newClearsignEncoder(getTestEntity(t), fixedTime) @@ -339,7 +337,6 @@ func TestGroupSigner_Sign(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { di, err := tt.gs.sign(context.Background()) if (err != nil) != tt.wantErr { @@ -534,7 +531,6 @@ func TestNewSigner(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { s, err := NewSigner(tt.fi, tt.opts...) if got, want := err, tt.wantErr; !errors.Is(got, want) { @@ -827,8 +823,6 @@ func TestSigner_Sign(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { b, err := os.ReadFile(filepath.Join(corpus, tt.inputFile)) if err != nil { diff --git a/pkg/integrity/verify_test.go b/pkg/integrity/verify_test.go index cebeb5ba..dbea56f0 100644 --- a/pkg/integrity/verify_test.go +++ b/pkg/integrity/verify_test.go @@ -51,7 +51,6 @@ func TestGroupVerifier_signatures(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { v := &groupVerifier{ f: tt.f, @@ -144,7 +143,6 @@ func TestGroupVerifier_verify(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { ods := make([]sif.Descriptor, len(tt.objectIDs)) for i, id := range tt.objectIDs { @@ -211,7 +209,6 @@ func TestLegacyGroupVerifier_signatures(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { v := &legacyGroupVerifier{ f: tt.f, @@ -279,7 +276,6 @@ func TestLegacyGroupVerifier_verify(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { ods, err := getGroupObjects(tt.f, tt.groupID) if err != nil { @@ -344,7 +340,6 @@ func TestLegacyObjectVerifier_signatures(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { od, err := tt.f.GetDescriptor(sif.WithID(tt.id)) if err != nil { @@ -420,7 +415,6 @@ func TestLegacyObjectVerifier_verify(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { od, err := tt.f.GetDescriptor(sif.WithID(tt.id)) if err != nil { @@ -677,7 +671,6 @@ func TestNewVerifier(t *testing.T) { //nolint:maintidx } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { v, err := NewVerifier(tt.fi, tt.opts...) if got, want := err, tt.wantErr; !errors.Is(got, want) { @@ -845,7 +838,6 @@ func TestVerifier_AnySignedBy(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { v := Verifier{tasks: tt.tasks} @@ -941,7 +933,6 @@ func TestVerifier_AllSignedBy(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { v := Verifier{tasks: tt.tasks} @@ -1097,7 +1088,6 @@ func TestVerifier_Verify(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { var vr VerifyResult diff --git a/pkg/sif/descriptor_test.go b/pkg/sif/descriptor_test.go index ac6125b2..63fc11fa 100644 --- a/pkg/sif/descriptor_test.go +++ b/pkg/sif/descriptor_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2023, Sylabs Inc. All rights reserved. +// Copyright (c) 2018-2024, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the // LICENSE file distributed with the sources of this project regarding your // rights to use or distribute this software. @@ -521,7 +521,6 @@ func TestDescriptor_GetIntegrityReader(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { d := Descriptor{ raw: rd, diff --git a/pkg/sif/load_test.go b/pkg/sif/load_test.go index d7e241e4..78f0681a 100644 --- a/pkg/sif/load_test.go +++ b/pkg/sif/load_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved. +// Copyright (c) 2018-2024, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the // LICENSE file distributed with the sources of this project regarding your // rights to use or distribute this software. @@ -33,8 +33,6 @@ func TestLoadContainerFromPath(t *testing.T) { }, } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { f, err := LoadContainerFromPath(tt.path, tt.opts...) if err != nil { @@ -66,8 +64,6 @@ func TestLoadContainer(t *testing.T) { }, } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { rw, err := os.Open(filepath.Join(corpus, "one-group.sif")) if err != nil { diff --git a/pkg/sif/sif_test.go b/pkg/sif/sif_test.go index df67bea6..7f0b1ba5 100644 --- a/pkg/sif/sif_test.go +++ b/pkg/sif/sif_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Sylabs Inc. All rights reserved. +// Copyright (c) 2021-2024, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the // LICENSE file distributed with the sources of this project regarding your // rights to use or distribute this software. @@ -86,7 +86,6 @@ func TestHeader_GetIntegrityReader(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { b := bytes.Buffer{}