From 1371c774cd39af67e3e88d804a09be17d4020b20 Mon Sep 17 00:00:00 2001 From: Vlad Vitan Date: Wed, 4 Sep 2024 16:04:50 +0200 Subject: [PATCH] qrg: Fix linter errors --- pkg/qrcodegenerator/grpc_gateways.go | 10 ++++++++-- pkg/qrcodegenerator/grpc_gateways_test.go | 9 +++++++-- pkg/qrcodegenerator/qrcode/gateways/gateways.go | 5 +++-- .../qrcode/gateways/gateways_test.go | 9 +++++++-- pkg/qrcodegenerator/qrcode/gateways/ttigpro1.go | 14 +++++++------- .../qrcode/gateways/ttigpro1_test.go | 13 +++++++++++++ pkg/qrcodegenerator/qrcodegenerator.go | 4 ++-- 7 files changed, 47 insertions(+), 17 deletions(-) diff --git a/pkg/qrcodegenerator/grpc_gateways.go b/pkg/qrcodegenerator/grpc_gateways.go index c09372f304..0d71101cf7 100644 --- a/pkg/qrcodegenerator/grpc_gateways.go +++ b/pkg/qrcodegenerator/grpc_gateways.go @@ -28,7 +28,10 @@ type gatewayQRCodeGeneratorServer struct { } // GetFormat implements EndDeviceQRCodeGenerator. -func (s *gatewayQRCodeGeneratorServer) GetFormat(ctx context.Context, req *ttnpb.GetQRCodeFormatRequest) (*ttnpb.QRCodeFormat, error) { +func (s *gatewayQRCodeGeneratorServer) GetFormat( + ctx context.Context, + req *ttnpb.GetQRCodeFormatRequest, +) (*ttnpb.QRCodeFormat, error) { _, err := rpcmetadata.WithForwardedAuth(ctx, s.QRG.AllowInsecureForCredentials()) if err != nil { return nil, err @@ -41,7 +44,10 @@ func (s *gatewayQRCodeGeneratorServer) GetFormat(ctx context.Context, req *ttnpb } // Parse implements EndDeviceQRCodeGenerator. -func (s *gatewayQRCodeGeneratorServer) Parse(ctx context.Context, req *ttnpb.ParseGatewayQRCodeRequest) (*ttnpb.ParseGatewayQRCodeResponse, error) { +func (s *gatewayQRCodeGeneratorServer) Parse( + ctx context.Context, + req *ttnpb.ParseGatewayQRCodeRequest, +) (*ttnpb.ParseGatewayQRCodeResponse, error) { _, err := rpcmetadata.WithForwardedAuth(ctx, s.QRG.AllowInsecureForCredentials()) if err != nil { return nil, err diff --git a/pkg/qrcodegenerator/grpc_gateways_test.go b/pkg/qrcodegenerator/grpc_gateways_test.go index 48bdbabc5c..a772faf216 100644 --- a/pkg/qrcodegenerator/grpc_gateways_test.go +++ b/pkg/qrcodegenerator/grpc_gateways_test.go @@ -22,7 +22,8 @@ import ( componenttest "go.thethings.network/lorawan-stack/v3/pkg/component/test" "go.thethings.network/lorawan-stack/v3/pkg/errors" "go.thethings.network/lorawan-stack/v3/pkg/log" - . "go.thethings.network/lorawan-stack/v3/pkg/qrcodegenerator" + "go.thethings.network/lorawan-stack/v3/pkg/qrcodegenerator" + "go.thethings.network/lorawan-stack/v3/pkg/qrcodegenerator/qrcode/gateways" "go.thethings.network/lorawan-stack/v3/pkg/ttnpb" "go.thethings.network/lorawan-stack/v3/pkg/util/test" @@ -35,7 +36,10 @@ func TestGatewayQRCodeParsing(t *testing.T) { c := componenttest.NewComponent(t, &component.Config{}) ttigpro1 := new(gateways.TTIGPRO1Format) - qrg, err := New(c, &Config{}, WithGatewayFormat(ttigpro1.ID(), ttigpro1)) + qrg, err := qrcodegenerator.New(c, + &qrcodegenerator.Config{}, + qrcodegenerator.WithGatewayFormat(ttigpro1.ID(), ttigpro1), + ) test.Must(qrg, err) componenttest.StartComponent(t, c) @@ -45,6 +49,7 @@ func TestGatewayQRCodeParsing(t *testing.T) { client := ttnpb.NewGatewayQRCodeGeneratorClient(c.LoopbackConn()) + //nolint:parralleltest for _, tc := range []struct { Name string FormatID string diff --git a/pkg/qrcodegenerator/qrcode/gateways/gateways.go b/pkg/qrcodegenerator/qrcode/gateways/gateways.go index 21e4d4ba03..b50d3d4ddd 100644 --- a/pkg/qrcodegenerator/qrcode/gateways/gateways.go +++ b/pkg/qrcodegenerator/qrcode/gateways/gateways.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Package gateways provides a QR code parser for gateways. package gateways import ( @@ -55,13 +56,13 @@ type Server struct { } // New returns a new Server. -func New(ctx context.Context) *Server { +func New(_ context.Context) *Server { s := &Server{ // Newer formats should be added to this slice first to // preferentially match with those first. gatewayFormats: []gatewayFormat{ { - id: formatIDttigpro1, + id: formatIDTTIGPRO1, format: new(TTIGPRO1Format), }, }, diff --git a/pkg/qrcodegenerator/qrcode/gateways/gateways_test.go b/pkg/qrcodegenerator/qrcode/gateways/gateways_test.go index b362ff3e24..4dde02c504 100644 --- a/pkg/qrcodegenerator/qrcode/gateways/gateways_test.go +++ b/pkg/qrcodegenerator/qrcode/gateways/gateways_test.go @@ -20,12 +20,14 @@ import ( "testing" "github.com/smarty/assertions" - . "go.thethings.network/lorawan-stack/v3/pkg/qrcodegenerator/qrcode/gateways" + "go.thethings.network/lorawan-stack/v3/pkg/qrcodegenerator/qrcode/gateways" "go.thethings.network/lorawan-stack/v3/pkg/util/test" "go.thethings.network/lorawan-stack/v3/pkg/util/test/assertions/should" ) func TestParseGatewaysAuthenticationCodes(t *testing.T) { + t.Parallel() + for i, tc := range []struct { FormatID string Data []byte @@ -39,10 +41,13 @@ func TestParseGatewaysAuthenticationCodes(t *testing.T) { ExpectedOwnerToken: "abcdef123456", }, } { + tc := tc + t.Run(strconv.Itoa(i), func(t *testing.T) { + t.Parallel() a := assertions.New(t) - qrCode := New(context.Background()) + qrCode := gateways.New(context.Background()) d, err := qrCode.Parse(tc.FormatID, tc.Data) data := test.Must(d, err) diff --git a/pkg/qrcodegenerator/qrcode/gateways/ttigpro1.go b/pkg/qrcodegenerator/qrcode/gateways/ttigpro1.go index 775fe6136b..e42284121f 100644 --- a/pkg/qrcodegenerator/qrcode/gateways/ttigpro1.go +++ b/pkg/qrcodegenerator/qrcode/gateways/ttigpro1.go @@ -22,7 +22,7 @@ import ( ) const ( - formatIDttigpro1 = "ttigpro1" + formatIDTTIGPRO1 = "ttigpro1" euiLength = 16 ownerTokenLength = 12 @@ -35,7 +35,7 @@ type ttigpro1 struct { } // ttigpro1Regex is the regular expression to match the TTIGPRO1 format. -// The format is as follows: https://ttig.pro/c/{16 lowercase base16 chars}/{12 base62 chars} +// The format is as follows: https://ttig.pro/c/{16 lowercase base16 chars}/{12 base62 chars}. var ttigpro1Regex = regexp.MustCompile(`^https://ttig\.pro/c/([a-f0-9]{16})/([a-z0-9]{12})$`) // UnmarshalText implements the TextUnmarshaler interface. @@ -60,8 +60,8 @@ func (m *ttigpro1) UnmarshalText(text []byte) error { } // FormatID implements the Data interface. -func (m *ttigpro1) FormatID() string { - return formatIDttigpro1 +func (*ttigpro1) FormatID() string { + return formatIDTTIGPRO1 } func (m *ttigpro1) GatewayEUI() types.EUI64 { @@ -69,7 +69,7 @@ func (m *ttigpro1) GatewayEUI() types.EUI64 { } func (m *ttigpro1) OwnerToken() string { - return string(m.ownerToken) + return m.ownerToken } // TTIGPRO1Format implements the TTIGPRO1 Format. @@ -79,7 +79,7 @@ type TTIGPRO1Format struct{} func (TTIGPRO1Format) Format() *ttnpb.QRCodeFormat { return &ttnpb.QRCodeFormat{ Name: "TTIGPRO1", - Description: "TTI QR code format for gateway devices.", + Description: "QR code format for The Things Indoor Gateway Pro.", FieldMask: ttnpb.FieldMask( "ids.eui", "claim_authentication_code.secret.value", @@ -89,7 +89,7 @@ func (TTIGPRO1Format) Format() *ttnpb.QRCodeFormat { // ID is the identifier of the format as a string. func (TTIGPRO1Format) ID() string { - return formatIDttigpro1 + return formatIDTTIGPRO1 } // New implements the Format interface. diff --git a/pkg/qrcodegenerator/qrcode/gateways/ttigpro1_test.go b/pkg/qrcodegenerator/qrcode/gateways/ttigpro1_test.go index 77de18bfe9..2d404a7495 100644 --- a/pkg/qrcodegenerator/qrcode/gateways/ttigpro1_test.go +++ b/pkg/qrcodegenerator/qrcode/gateways/ttigpro1_test.go @@ -24,7 +24,11 @@ import ( ) func TestTTIGPRO1(t *testing.T) { + t.Parallel() + t.Run("Decode", func(t *testing.T) { + t.Parallel() + for _, tc := range []struct { Name string Data []byte @@ -43,6 +47,7 @@ func TestTTIGPRO1(t *testing.T) { Name: "InvalidURLPrefix", Data: []byte("https://example.com/c/ec656efffe000128/abcdef12"), ErrorAssertion: func(t *testing.T, err error) bool { + t.Helper() return assertions.New(t).So(errors.IsInvalidArgument(err), should.BeTrue) }, }, @@ -50,6 +55,7 @@ func TestTTIGPRO1(t *testing.T) { Name: "Invalid/EUINotLowercase", Data: []byte("https://ttig.pro/c/EC656effFe000128/abcdef12"), ErrorAssertion: func(t *testing.T, err error) bool { + t.Helper() return assertions.New(t).So(errors.IsInvalidArgument(err), should.BeTrue) }, }, @@ -57,6 +63,7 @@ func TestTTIGPRO1(t *testing.T) { Name: "Invalid/EUILength", Data: []byte("https://ttig.pro/c/ec656efffe00012/abcdef12"), ErrorAssertion: func(t *testing.T, err error) bool { + t.Helper() return assertions.New(t).So(errors.IsInvalidArgument(err), should.BeTrue) }, }, @@ -64,6 +71,7 @@ func TestTTIGPRO1(t *testing.T) { Name: "Invalid/EUINotBase16", Data: []byte("https://ttig.pro/c/ec656efffe00012g/abcdef12"), ErrorAssertion: func(t *testing.T, err error) bool { + t.Helper() return assertions.New(t).So(errors.IsInvalidArgument(err), should.BeTrue) }, }, @@ -71,6 +79,7 @@ func TestTTIGPRO1(t *testing.T) { Name: "Invalid/OwnerTokenLength", Data: []byte("https://ttig.pro/c/ec656efffe000128/abcdef123"), ErrorAssertion: func(t *testing.T, err error) bool { + t.Helper() return assertions.New(t).So(errors.IsInvalidArgument(err), should.BeTrue) }, }, @@ -78,11 +87,15 @@ func TestTTIGPRO1(t *testing.T) { Name: "Invalid/OwnerTokenNotBase62", Data: []byte("https://ttig.pro/c/ec656efffe000128/abcdef12!"), ErrorAssertion: func(t *testing.T, err error) bool { + t.Helper() return assertions.New(t).So(errors.IsInvalidArgument(err), should.BeTrue) }, }, } { + tc := tc t.Run(tc.Name, func(t *testing.T) { + t.Parallel() + a := assertions.New(t) var data ttigpro1 diff --git a/pkg/qrcodegenerator/qrcodegenerator.go b/pkg/qrcodegenerator/qrcodegenerator.go index 8a79e3d0fc..f6917d0605 100644 --- a/pkg/qrcodegenerator/qrcodegenerator.go +++ b/pkg/qrcodegenerator/qrcodegenerator.go @@ -103,6 +103,6 @@ func (qrg *QRCodeGenerator) RegisterServices(s *grpc.Server) { // RegisterHandlers registers gRPC handlers. func (qrg *QRCodeGenerator) RegisterHandlers(s *runtime.ServeMux, conn *grpc.ClientConn) { - ttnpb.RegisterEndDeviceQRCodeGeneratorHandler(qrg.Context(), s, conn) - ttnpb.RegisterGatewayQRCodeGeneratorHandler(qrg.Context(), s, conn) + ttnpb.RegisterEndDeviceQRCodeGeneratorHandler(qrg.Context(), s, conn) //nolint:errcheck + ttnpb.RegisterGatewayQRCodeGeneratorHandler(qrg.Context(), s, conn) //nolint:errcheck }