storj/pkg/pool/connection_pool_test.go
Egon Elbre fe3decc42f
all: fix govet warnings (#255)
Fixes go1.11 vet warnings.

Cancel on WithTimeout must always be called to avoid memory leak:

pkg/provider/provider.go:73: the cancel function returned by context.WithTimeout should be called, not discarded, to avoid a context leak

Range over non-copyable things:

pkg/pool/connection_pool_test.go:32: range var v copies lock: struct{pool pool.ConnectionPool; key string; expected pool.TestFoo; expectedError error} contains pool.ConnectionPool contains sync.RWMutex
pkg/pool/connection_pool_test.go:56: range var v copies lock: struct{pool pool.ConnectionPool; key string; value pool.TestFoo; expected pool.TestFoo; expectedError error} contains pool.ConnectionPool contains sync.RWMutex
pkg/pool/connection_pool_test.go:83: range var v copies lock: struct{pool pool.ConnectionPool; key string; value pool.TestFoo; expected interface{}; expectedError error} contains pool.ConnectionPool contains sync.RWMutex

zeebo/errs package always requires formatting directives:

pkg/peertls/peertls.go:50: Class.New call has arguments but no formatting directives
pkg/peertls/utils.go:47: Class.New call has arguments but no formatting directives
pkg/peertls/utils.go:87: Class.New call has arguments but no formatting directives
pkg/overlay/cache.go:94: Class.New call has arguments but no formatting directives
pkg/provider/certificate_authority.go:98: New call has arguments but no formatting directives
pkg/provider/identity.go:96: New call has arguments but no formatting directives
pkg/provider/utils.go:124: New call needs 1 arg but has 2 args
pkg/provider/utils.go:136: New call needs 1 arg but has 2 args
storage/redis/client.go:44: Class.New call has arguments but no formatting directives
storage/redis/client.go:64: Class.New call has arguments but no formatting directives
storage/redis/client.go:75: Class.New call has arguments but no formatting directives
storage/redis/client.go:80: Class.New call has arguments but no formatting directives
storage/redis/client.go:92: Class.New call has arguments but no formatting directives
storage/redis/client.go:96: Class.New call has arguments but no formatting directives
storage/redis/client.go:102: Class.New call has arguments but no formatting directives
storage/redis/client.go:126: Class.New call has arguments but no formatting directives
2018-08-22 09:39:57 +03:00

96 lines
2.0 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package pool
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
type TestFoo struct {
called string
}
func TestGet(t *testing.T) {
cases := []struct {
pool ConnectionPool
key string
expected TestFoo
expectedError error
}{
{
pool: ConnectionPool{cache: map[string]interface{}{"foo": TestFoo{called: "hoot"}}},
key: "foo",
expected: TestFoo{called: "hoot"},
expectedError: nil,
},
}
for i := range cases {
v := &cases[i]
test, err := v.pool.Get(context.Background(), v.key)
assert.Equal(t, v.expectedError, err)
assert.Equal(t, v.expected, test)
}
}
func TestAdd(t *testing.T) {
cases := []struct {
pool ConnectionPool
key string
value TestFoo
expected TestFoo
expectedError error
}{
{
pool: ConnectionPool{cache: map[string]interface{}{}},
key: "foo",
value: TestFoo{called: "hoot"},
expected: TestFoo{called: "hoot"},
expectedError: nil,
},
}
for i := range cases {
v := &cases[i]
err := v.pool.Add(context.Background(), v.key, v.value)
assert.Equal(t, v.expectedError, err)
test, err := v.pool.Get(context.Background(), v.key)
assert.Equal(t, v.expectedError, err)
assert.Equal(t, v.expected, test)
}
}
func TestRemove(t *testing.T) {
cases := []struct {
pool ConnectionPool
key string
value TestFoo
expected interface{}
expectedError error
}{
{
pool: ConnectionPool{cache: map[string]interface{}{"foo": TestFoo{called: "hoot"}}},
key: "foo",
expected: nil,
expectedError: nil,
},
}
for i := range cases {
v := &cases[i]
err := v.pool.Remove(context.Background(), v.key)
assert.Equal(t, v.expectedError, err)
test, err := v.pool.Get(context.Background(), v.key)
assert.Equal(t, v.expectedError, err)
assert.Equal(t, v.expected, test)
}
}