Skip to content

Commit

Permalink
linting post buf/grpc update
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Sep 22, 2024
1 parent 3240a6d commit 5df21e5
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 7 deletions.
10 changes: 5 additions & 5 deletions artifact/cmd/artifact/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func mainWithArgs(ctx context.Context, args []string, logger utils.ZapCompatible
}
switch topArgsParsed.Command {
case commandNameClean:
//nolint:contextcheck

if err := tools.Clean(); err != nil {
logger.Fatal(err)
}
Expand All @@ -57,12 +57,12 @@ func mainWithArgs(ctx context.Context, args []string, logger utils.ZapCompatible
if err := utils.ParseFlags(utils.StringSliceRemove(args, 1), &pullArgsParsed); err != nil {
return err
}
//nolint:contextcheck

if err := tools.Pull(pullArgsParsed.TreePath, pullArgsParsed.All); err != nil {
logger.Fatal(err)
}
case commandNamePush:
//nolint:contextcheck

if err := tools.Push(); err != nil {
logger.Fatal(err)
}
Expand All @@ -71,12 +71,12 @@ func mainWithArgs(ctx context.Context, args []string, logger utils.ZapCompatible
if err := utils.ParseFlags(utils.StringSliceRemove(args, 1), &removeArgsParsed); err != nil {
return err
}
//nolint:contextcheck

if err := tools.Remove(removeArgsParsed.Path); err != nil {
logger.Fatal(err)
}
case commandNameStatus:
//nolint:contextcheck

status, err := tools.Status()
if err != nil {
logger.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type ZapCompatibleLogger interface {
// calling its `Sublogger` method if it is an RDK logger, or its `Named` method if it is a Zap logger.
// If neither method is available, it logs a debug message and returns the original logger.
func Sublogger(inp ZapCompatibleLogger, subname string) (loggerRet ZapCompatibleLogger) {
loggerRet = inp //nolint:wastedassign
loggerRet = inp

// loggerRet is initialized to inp as a return value and is intentionally never re-assigned
// before calling functions that can panic so that defer + recover returns the original logger
Expand Down Expand Up @@ -88,7 +88,7 @@ func Sublogger(inp ZapCompatibleLogger, subname string) (loggerRet ZapCompatible
// calling its `WithFields` method if it is an RDK logger, or its `With` method if it is a Zap logger.
// If neither method is available, it logs a debug message and returns the original logger.
func AddFieldsToLogger(inp ZapCompatibleLogger, args ...interface{}) (loggerRet ZapCompatibleLogger) {
loggerRet = inp //nolint:wastedassign
loggerRet = inp

// loggerRet is initialized to inp as a return value and is intentionally never re-assigned
// before calling functions that can panic so that defer + recover returns the original logger
Expand Down
3 changes: 3 additions & 0 deletions rpc/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (cd *cachedDialer) DialDirect(
opts ...grpc.DialOption,
) (ClientConn, bool, error) {
return cd.DialFunc("grpc", target, keyExtra, func() (ClientConn, func() error, error) {
//nolint:staticcheck
conn, err := grpc.DialContext(ctx, target, opts...)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -243,6 +244,7 @@ func DialDirectGRPC(ctx context.Context, address string, logger utils.ZapCompati
// dialDirectGRPC dials a gRPC server directly.
func dialDirectGRPC(ctx context.Context, address string, dOpts dialOptions, logger utils.ZapCompatibleLogger) (ClientConn, bool, error) {
dialOpts := []grpc.DialOption{
//nolint:staticcheck
grpc.WithBlock(),
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxMessageSize)),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Expand Down Expand Up @@ -374,6 +376,7 @@ func dialDirectGRPC(ctx context.Context, address string, dOpts dialOptions, logg
conn, cached, err = ctxDialer.DialDirect(ctx, address, dOpts.cacheKey(), closeCredsFunc, dialOpts...)
} else {
var grpcConn *grpc.ClientConn
//nolint:staticcheck
grpcConn, err = grpc.DialContext(ctx, address, dialOpts...)
if err == nil {
conn = GrpcOverHTTPClientConn{grpcConn}
Expand Down
5 changes: 5 additions & 0 deletions rpc/dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestCachedDialer(t *testing.T) {
"",
closeChecker,
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock())
test.That(t, err, test.ShouldBeNil)
test.That(t, cached, test.ShouldBeFalse)
Expand All @@ -68,6 +69,7 @@ func TestCachedDialer(t *testing.T) {
"",
closeChecker,
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock())
test.That(t, err, test.ShouldBeNil)
test.That(t, cached, test.ShouldBeTrue)
Expand All @@ -77,6 +79,7 @@ func TestCachedDialer(t *testing.T) {
"more",
closeChecker2,
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock())
test.That(t, err, test.ShouldBeNil)
test.That(t, cached, test.ShouldBeFalse)
Expand All @@ -86,6 +89,7 @@ func TestCachedDialer(t *testing.T) {
"",
closeChecker3,
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock())
test.That(t, err, test.ShouldBeNil)
test.That(t, cached, test.ShouldBeFalse)
Expand Down Expand Up @@ -127,6 +131,7 @@ func TestCachedDialer(t *testing.T) {
"",
closeChecker,
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock())
test.That(t, err, test.ShouldBeNil)
test.That(t, cached, test.ShouldBeFalse)
Expand Down
2 changes: 2 additions & 0 deletions rpc/interceptors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ func TestTracingInterceptors(t *testing.T) {

// gRPC
grpcOpts := []grpc.DialOption{
//nolint:staticcheck
grpc.WithBlock(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithUnaryInterceptor(UnaryClientTracingInterceptor()),
grpc.WithStreamInterceptor(StreamClientTracingInterceptor()),
}

//nolint:staticcheck
conn, err := grpc.DialContext(ctx, listener.Addr().String(), grpcOpts...)
test.That(t, err, test.ShouldBeNil)
defer func() {
Expand Down
2 changes: 2 additions & 0 deletions rpc/server_auth_jwks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ func TestJWKSKeyProviderAndEmailLoader(t *testing.T) {

// standard grpc
t.Run("standard grpc", func(t *testing.T) {
//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down
28 changes: 28 additions & 0 deletions rpc/server_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ func TestServerAuth(t *testing.T) {

// standard grpc
t.Run("standard grpc", func(t *testing.T) {
//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -229,10 +231,12 @@ func TestServerAuth(t *testing.T) {
fakeAuthWorks = true
testMu.Unlock()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -292,10 +296,12 @@ func TestServerAuth(t *testing.T) {
test.That(t, httpResp3.StatusCode, test.ShouldEqual, 401)

// works from here
//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -363,10 +369,12 @@ func TestServerAuthJWTExpiration(t *testing.T) {
errChan <- rpcServer.Serve(httpListener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -457,10 +465,12 @@ func TestServerAuthJWTAudienceAndID(t *testing.T) {
errChan <- rpcServer.Serve(httpListener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -557,6 +567,7 @@ func TestServerPublicMethods(t *testing.T) {
listener, err := net.Listen("tcp", "localhost:0")
test.That(t, err, test.ShouldBeNil)
grpcOpts := []grpc.DialOption{
//nolint:staticcheck
grpc.WithBlock(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
}
Expand All @@ -566,6 +577,7 @@ func TestServerPublicMethods(t *testing.T) {
errChan <- rpcServer.Serve(listener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(context.Background(), listener.Addr().String(), grpcOpts...)
test.That(t, err, test.ShouldBeNil)
defer func() {
Expand Down Expand Up @@ -617,6 +629,7 @@ func TestServerPublicMethods(t *testing.T) {
listener, err := net.Listen("tcp", "localhost:0")
test.That(t, err, test.ShouldBeNil)
grpcOpts := []grpc.DialOption{
//nolint:staticcheck
grpc.WithBlock(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
}
Expand All @@ -626,6 +639,7 @@ func TestServerPublicMethods(t *testing.T) {
errChan <- rpcServer.Serve(listener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(context.Background(), listener.Addr().String(), grpcOpts...)
test.That(t, err, test.ShouldBeNil)
defer func() {
Expand Down Expand Up @@ -711,10 +725,12 @@ func TestServerAuthKeyFunc(t *testing.T) {
errChan <- rpcServer.Serve(httpListener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -813,10 +829,12 @@ func TestServerAuthToHandler(t *testing.T) {
errChan <- rpcServer.Serve(httpListener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -964,10 +982,12 @@ func TestServerOptionWithAuthIssuer(t *testing.T) {
errChan <- rpcServer.Serve(httpListener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -1099,10 +1119,12 @@ func TestServerAuthToHandlerWithJWKSetTokenVerifier(t *testing.T) {
errChan <- rpcServer.Serve(httpListener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -1225,10 +1247,12 @@ func TestServerAuthToHandlerWithExternalAuthOIDCTokenVerifier(t *testing.T) {
errChan <- rpcServer.Serve(httpListener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -1366,10 +1390,12 @@ func TestServerAuthMultiKey(t *testing.T) {
errChan <- rpcServer.Serve(httpListener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -1505,10 +1531,12 @@ func TestServerAuthRSA(t *testing.T) {
errChan <- rpcServer.Serve(httpListener)
}()

//nolint:staticcheck
conn, err := grpc.DialContext(
context.Background(),
httpListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
//nolint:staticcheck
grpc.WithBlock(),
)
test.That(t, err, test.ShouldBeNil)
Expand Down
2 changes: 2 additions & 0 deletions rpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestServer(t *testing.T) {
RootCAs: certPool,
ServerName: "localhost",
}
//nolint:staticcheck
grpcOpts := []grpc.DialOption{grpc.WithBlock()}
if secure {
grpcOpts = append(
Expand All @@ -113,6 +114,7 @@ func TestServer(t *testing.T) {
} else {
grpcOpts = append(grpcOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
//nolint:staticcheck
conn, err := grpc.DialContext(context.Background(), listener.Addr().String(), grpcOpts...)
test.That(t, err, test.ShouldBeNil)
defer func() {
Expand Down
1 change: 1 addition & 0 deletions rpc/wrtc_signaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func testWebRTCSignaling(t *testing.T, signalingCallQueue WebRTCCallQueue, logge
)
answerer.Start()

//nolint:staticcheck
cc, err := grpc.Dial(grpcListener.Addr().String(), grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
test.That(t, err, test.ShouldBeNil)
defer func() {
Expand Down

0 comments on commit 5df21e5

Please sign in to comment.