Skip to content

Commit

Permalink
jettison: Use error Option
Browse files Browse the repository at this point in the history
Summary:
Upgrade jettison Options
  • Loading branch information
adamhicks committed Jul 19, 2023
1 parent 6229ca0 commit 92be16f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
go: ['1.18', '1.19', '1.20']
go: ['1.20']

services:
etcd:
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ vet:
unit_test:
parallel:
matrix:
- GO: ["1.18", "1.19", "1.20"]
- GO: ["1.20"]
image:
name: golang:$GO
stage: test
Expand Down
29 changes: 13 additions & 16 deletions v2/go.mod
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
module github.com/luno/rink/v2

go 1.19
go 1.20

require (
github.com/dgryski/go-jump v0.0.0-20170409065014-e1f439676b57
github.com/luno/jettison v0.0.0-20220927134759-09187a35ec8c
github.com/stretchr/testify v1.7.1
github.com/luno/jettison v0.0.0-20230718160357-e090ef1681b1
github.com/stretchr/testify v1.8.1
go.etcd.io/etcd/client/v3 v3.5.0
go.uber.org/zap v1.17.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/grpc v1.38.0
google.golang.org/grpc v1.56.0
)

require (
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/exp/errors v0.0.0-20200331195152-e8c3332aa8e5 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
53 changes: 33 additions & 20 deletions v2/go.sum

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions v2/rink.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"time"

"github.com/luno/jettison"
"github.com/luno/jettison/errors"
"github.com/luno/jettison/j"
"github.com/luno/jettison/log"
Expand All @@ -15,9 +14,9 @@ import (

type noopLogger struct{}

func (noopLogger) Debug(context.Context, string, ...jettison.Option) {}
func (noopLogger) Info(context.Context, string, ...jettison.Option) {}
func (noopLogger) Error(context.Context, error, ...jettison.Option) {}
func (noopLogger) Debug(context.Context, string, ...log.Option) {}
func (noopLogger) Info(context.Context, string, ...log.Option) {}
func (noopLogger) Error(context.Context, error, ...log.Option) {}

type options struct {
Log log.Interface
Expand Down
15 changes: 8 additions & 7 deletions v2/rink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"
"time"

"github.com/luno/jettison"
"github.com/luno/jettison/jtest"
"github.com/luno/jettison/log"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -104,21 +103,22 @@ func makeLogger() *logCounter {
return &logCounter{counts: make(map[string]int)}
}

func (l *logCounter) Debug(ctx context.Context, msg string, ol ...jettison.Option) {
func (l *logCounter) Debug(ctx context.Context, msg string, ol ...log.Option) {
l.mu.Lock()
defer l.mu.Unlock()
ol = append(ol, log.WithLevel(log.LevelDebug))
log.Info(ctx, msg, ol...)
l.counts["debug"] += 1
}
func (l *logCounter) Info(ctx context.Context, msg string, ol ...jettison.Option) {

func (l *logCounter) Info(ctx context.Context, msg string, ol ...log.Option) {
l.mu.Lock()
defer l.mu.Unlock()
log.Info(ctx, msg, ol...)
l.counts["info"] += 1
}

func (l *logCounter) Error(ctx context.Context, err error, ol ...jettison.Option) {
func (l *logCounter) Error(ctx context.Context, err error, ol ...log.Option) {
l.mu.Lock()
defer l.mu.Unlock()
log.Error(ctx, err, ol...)
Expand Down Expand Up @@ -178,15 +178,17 @@ func TestBuildOptions(t *testing.T) {

expOptions options
}{
{name: "logger defaulted to cluster and roles",
{
name: "logger defaulted to cluster and roles",
opts: []Option{WithLogger(l1)},
expOptions: options{
Log: l1,
ClusterOptions: ClusterOptions{Log: l1},
RolesOptions: RolesOptions{Log: l1},
},
},
{name: "can specify separate logger for cluster and roles",
{
name: "can specify separate logger for cluster and roles",
opts: []Option{
WithLogger(l1),
WithClusterOptions(ClusterOptions{Log: l2}),
Expand All @@ -211,5 +213,4 @@ func TestBuildOptions(t *testing.T) {
assert.Equal(t, tc.expOptions.ClusterOptions.NewMemberWait, o.ClusterOptions.NewMemberWait)
})
}

}
14 changes: 7 additions & 7 deletions v2/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"
"time"

"github.com/luno/jettison"
"github.com/luno/jettison/errors"
"github.com/luno/jettison/jtest"
"github.com/luno/jettison/log"
Expand Down Expand Up @@ -40,17 +39,17 @@ type testLogger struct {
testing.TB
}

func (t testLogger) Debug(ctx context.Context, msg string, ol ...jettison.Option) {
func (t testLogger) Debug(ctx context.Context, msg string, ol ...log.Option) {
t.Log("DEBUG", msg)
log.Debug(ctx, msg, ol...)
}

func (t testLogger) Info(ctx context.Context, msg string, ol ...jettison.Option) {
func (t testLogger) Info(ctx context.Context, msg string, ol ...log.Option) {
t.Log("INFO", msg)
log.Info(ctx, msg, ol...)
}

func (t testLogger) Error(ctx context.Context, err error, ol ...jettison.Option) {
func (t testLogger) Error(ctx context.Context, err error, ol ...log.Option) {
t.Log("ERROR", err)
log.Error(ctx, err, ol...)
}
Expand Down Expand Up @@ -221,7 +220,6 @@ func TestRoles_MutexAlreadyLocked(t *testing.T) {

_, _, err = r.AwaitRoleContext(context.Background(), "test")
jtest.AssertNil(t, err)

}

func TestRoles_AwaitCancel(t *testing.T) {
Expand Down Expand Up @@ -323,11 +321,13 @@ func TestRoles_MutexKeys(t *testing.T) {
expKey string
}{
{name: "empty", expKey: "roles"},
{name: "namespace only",
{
name: "namespace only",
namespace: "test",
expKey: "test/roles",
},
{name: "full key",
{
name: "full key",
namespace: "hello",
role: "world",
expKey: "hello/roles/world",
Expand Down

0 comments on commit 92be16f

Please sign in to comment.