diff --git a/.drone.yml b/.drone.yml index 8fa4d94..1c6ddef 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,7 +10,8 @@ steps: - name: test image: golang commands: - - go test -parallel 10 -race ./... + # - go test -parallel 10 -race ./... + - go test -race ./... - name: golangci-lint image: golangci/golangci-lint:v1.53 diff --git a/.golangci.yml b/.golangci.yml index 29a6459..6c7c222 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -43,6 +43,8 @@ linters: - ifshort - nosnakecase + - ireturn # implement provider interface + issues: # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: diff --git a/client.go b/client.go index 15739e0..d5928f7 100644 --- a/client.go +++ b/client.go @@ -124,7 +124,6 @@ func (c *Client) Value(ctx context.Context, path ...string) (Value, error) { } func (c *Client) Watch(ctx context.Context, callback WatchCallback, path ...string) error { - for idx, prov := range c.providers { provider, ok := prov.(WatchProvider) if !ok { diff --git a/provider/arg/provider.go b/provider/arg/provider.go index e9b2228..6104f19 100644 --- a/provider/arg/provider.go +++ b/provider/arg/provider.go @@ -106,7 +106,7 @@ func (p *Provider) Name() string { return p.name } -func (p *Provider) Value(ctx context.Context, path ...string) (config.Value, error) { +func (p *Provider) Value(_ context.Context, path ...string) (config.Value, error) { if err := p.parse(); err != nil { return nil, err } @@ -123,7 +123,11 @@ func (p *Provider) Value(ctx context.Context, path ...string) (config.Value, err } return value.Decode(func(v interface{}) error { - return json.Unmarshal(data, v) + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("unmarshal:%w", err) + } + + return nil }), nil } } diff --git a/provider/arg/provider_test.go b/provider/arg/provider_test.go index 2e759ea..b029e62 100644 --- a/provider/arg/provider_test.go +++ b/provider/arg/provider_test.go @@ -58,6 +58,7 @@ func (d *Duration) UnmarshalJSON(in []byte) error { if err != nil { return fmt.Errorf("parse:%w", err) } + d.Duration = o return nil diff --git a/provider/env/provider.go b/provider/env/provider.go index b287b34..161583d 100644 --- a/provider/env/provider.go +++ b/provider/env/provider.go @@ -45,7 +45,7 @@ func (p *Provider) Name() string { return p.name } -func (p *Provider) Value(ctx context.Context, path ...string) (config.Value, error) { +func (p *Provider) Value(_ context.Context, path ...string) (config.Value, error) { name := p.prefix + p.key(path...) if val, ok := os.LookupEnv(name); ok { return value.JString(val), nil diff --git a/provider/watcher/provider.go b/provider/watcher/provider.go index 4ab7561..dc286e0 100644 --- a/provider/watcher/provider.go +++ b/provider/watcher/provider.go @@ -67,7 +67,6 @@ func (p *Provider) Watch(ctx context.Context, callback config.WatchCallback, key return } p.logger(ctx, "callback %v:%v", key, err) - } oldVar = newVar } diff --git a/provider/watcher/provider_test.go b/provider/watcher/provider_test.go index ba5d8ba..68725b3 100644 --- a/provider/watcher/provider_test.go +++ b/provider/watcher/provider_test.go @@ -2,7 +2,7 @@ package watcher_test import ( "context" - "fmt" + "strconv" "sync" "sync/atomic" "testing" @@ -14,6 +14,8 @@ import ( "gitoa.ru/go-4devs/config/value" ) +var _ config.Provider = (*provider)(nil) + type provider struct { cnt int32 } @@ -25,7 +27,7 @@ func (p *provider) Name() string { func (p *provider) Value(context.Context, ...string) (config.Value, error) { p.cnt++ - return value.JString(fmt.Sprint(p.cnt)), nil + return value.JString(strconv.Itoa(int(p.cnt))), nil } func TestWatcher(t *testing.T) { @@ -57,6 +59,7 @@ func TestWatcher(t *testing.T) { }, "tmpname", ) + wg.Wait() require.NoError(t, err) diff --git a/test/provider_suite.go b/test/provider_suite.go index ea57537..cbb594d 100644 --- a/test/provider_suite.go +++ b/test/provider_suite.go @@ -26,10 +26,8 @@ func Run(t *testing.T, provider config.Provider, read []Read) { val, err := provider.Value(ctx, read.Key...) require.NoError(t, err, read.Key) read.Assert(t, val) - }) } - } type Read struct { diff --git a/value.go b/value.go index 26cd231..1095b9a 100644 --- a/value.go +++ b/value.go @@ -8,7 +8,7 @@ type Value interface { ReadValue ParseValue UnmarshalValue - IsEquals(Value) bool + IsEquals(in Value) bool } type UnmarshalValue interface {