Skip to content

Commit

Permalink
fix: lint && fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed Oct 22, 2024
1 parent 767003d commit fc3a007
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 6 additions & 2 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ func New(config Config) (*Agent, error) {
return nil, err
}
}
go a.serve()
go func() {
if err := a.serve(); err != nil {
logger.Fatal("agent failed", zap.Error(err))
}
}()
return a, nil
}

Expand Down Expand Up @@ -113,7 +117,7 @@ func (a *Agent) setupLog() error {
if _, err := reader.Read(b); err != nil {
return false
}
return bytes.Compare(b, []byte{byte(log.RaftRPC)}) == 0
return bytes.Equal(b, []byte{byte(log.RaftRPC)})
})
logConfig := log.Config{}
logConfig.Raft.StreamLayer = log.NewStreamLayer(
Expand Down
7 changes: 4 additions & 3 deletions internal/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/travisjeffery/go-dynaport"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/status"

api "github.com/garrettladley/dclog/api/v1"
"github.com/garrettladley/dclog/internal/agent"
Expand Down Expand Up @@ -123,8 +124,8 @@ func TestAgent(t *testing.T) {
)
require.Nil(t, consumeResponse)
require.Error(t, err)
got := grpc.Code(err)
want := grpc.Code(api.ErrOffsetOutOfRange{}.GRPCStatus().Err())
got := status.Code(err)
want := status.Code(api.ErrOffsetOutOfRange{}.GRPCStatus().Err())
require.Equal(t, got, want)
}

Expand All @@ -133,7 +134,7 @@ func client(t *testing.T, agent *agent.Agent, tlsConfig *tls.Config) api.LogClie
opts := []grpc.DialOption{grpc.WithTransportCredentials(tlsCreds)}
rpcAddr, err := agent.Config.RPCAddr()
require.NoError(t, err)
conn, err := grpc.Dial(rpcAddr, opts...)
conn, err := grpc.NewClient(rpcAddr, opts...)
require.NoError(t, err)
client := api.NewLogClient(conn)
return client
Expand Down
7 changes: 0 additions & 7 deletions internal/log/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,3 @@ func (s *segment) Remove() error {
}
return nil
}

func nearestMultiple(j, k uint64) uint64 {
if j >= 0 {
return (j / k) * k
}
return ((j - k + 1) / k) * k
}
6 changes: 4 additions & 2 deletions internal/log/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ func TestStoreClose(t *testing.T) {
_, _, err = s.Append(write)
require.NoError(t, err)

f, beforeSize, err := openFile(f.Name())
var beforeSize int64
f, beforeSize, err = openFile(f.Name())
require.NoError(t, err)

err = s.Close()
require.NoError(t, err)

f, afterSize, err := openFile(f.Name())
var afterSize int64
f, afterSize, err = openFile(f.Name())

Check failure on line 88 in internal/log/store_test.go

View workflow job for this annotation

GitHub Actions / Lint

ineffectual assignment to err (ineffassign)
require.True(t, afterSize > beforeSize)
}

Expand Down
10 changes: 5 additions & 5 deletions internal/server/server_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package server

import (
// ...
"context"
"flag"
"fmt"
"net"
"os"
"testing"
Expand All @@ -24,8 +24,6 @@ import (
"github.com/garrettladley/dclog/internal/log"
)

// imports...

var debug = flag.Bool("debug", false, "Enable observability for debugging.")

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -89,7 +87,7 @@ func setupTest(t *testing.T, fn func(*Config)) (
require.NoError(t, err)
tlsCreds := credentials.NewTLS(tlsConfig)
opts := []grpc.DialOption{grpc.WithTransportCredentials(tlsCreds)}
conn, err := grpc.Dial(l.Addr().String(), opts...)
conn, err := grpc.NewClient(l.Addr().String(), opts...)
require.NoError(t, err)
client := api.NewLogClient(conn)
return conn, client, opts
Expand Down Expand Up @@ -157,7 +155,9 @@ func setupTest(t *testing.T, fn func(*Config)) (
require.NoError(t, err)

go func() {
server.Serve(l)
if err := server.Serve(l); err != nil {
panic(fmt.Errorf("server serve: %w", err))
}
}()

return rootClient, nobodyClient, cfg, func() {
Expand Down

0 comments on commit fc3a007

Please sign in to comment.