storj/pkg/overlay/config_test.go

89 lines
2.0 KiB
Go
Raw Normal View History

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package overlay
import (
"context"
"net/url"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/zeebo/errs"
"storj.io/storj/pkg/kademlia"
)
func TestRun(t *testing.T) {
config := Config{}
bctx := context.Background()
kad := &kademlia.Kademlia{}
var key kademlia.CtxKey
cases := []struct {
testName string
testFunc func(t *testing.T)
}{
{
testName: "Run with nil",
testFunc: func(t *testing.T) {
err := config.Run(bctx, nil)
assert.Error(t, err)
assert.Equal(t, err.Error(), "overlay error: programmer error: kademlia responsibility unstarted")
},
},
{
testName: "Run with nil, pass pointer to Kademlia in context",
testFunc: func(t *testing.T) {
ctx := context.WithValue(bctx, key, kad)
err := config.Run(ctx, nil)
assert.Error(t, err)
assert.Equal(t, err.Error(), "overlay error: database scheme not supported: ")
},
},
{
testName: "db scheme redis conn fail",
testFunc: func(t *testing.T) {
ctx := context.WithValue(bctx, key, kad)
var config = Config{DatabaseURL: "redis://somedir/overlay.db/?db=1"}
err := config.Run(ctx, nil)
assert.Error(t, err)
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 07:39:57 +01:00
assert.Equal(t, err.Error(), "redis error: ping failed: dial tcp: address somedir: missing port in address")
},
},
{
testName: "db scheme bolt conn fail",
testFunc: func(t *testing.T) {
ctx := context.WithValue(bctx, key, kad)
var config = Config{DatabaseURL: "bolt://somedir/overlay.db"}
err := config.Run(ctx, nil)
assert.Error(t, err)
if !os.IsNotExist(errs.Unwrap(err)) {
t.Fatal(err.Error())
}
},
},
}
for _, c := range cases {
t.Run(c.testName, c.testFunc)
}
}
func TestUrlPwd(t *testing.T) {
res := GetUserPassword(nil)
assert.Equal(t, res, "")
uinfo := url.UserPassword("testUser", "testPassword")
uri := url.URL{User: uinfo}
res = GetUserPassword(&uri)
assert.Equal(t, res, "testPassword")
}