2018-08-03 14:15:52 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
2018-08-01 13:57:37 +01:00
|
|
|
package overlay
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-10-16 12:43:44 +01:00
|
|
|
|
2018-08-01 13:57:37 +01:00
|
|
|
"storj.io/storj/pkg/kademlia"
|
2018-11-27 17:46:12 +00:00
|
|
|
"storj.io/storj/pkg/statdb"
|
2018-08-01 13:57:37 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRun(t *testing.T) {
|
2018-11-27 17:46:12 +00:00
|
|
|
bctx := context.Background()
|
|
|
|
|
2018-08-01 13:57:37 +01:00
|
|
|
kad := &kademlia.Kademlia{}
|
2018-11-16 16:31:14 +00:00
|
|
|
var kadKey kademlia.CtxKey
|
2018-11-27 17:46:12 +00:00
|
|
|
ctx := context.WithValue(bctx, kadKey, kad)
|
|
|
|
|
|
|
|
sdb := &statdb.Server{}
|
|
|
|
var statKey statdb.CtxKey
|
|
|
|
ctx = context.WithValue(ctx, statKey, sdb)
|
2018-08-01 13:57:37 +01:00
|
|
|
|
2018-11-16 16:31:14 +00:00
|
|
|
// run with nil
|
|
|
|
err := Config{}.Run(context.Background(), nil)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, "overlay error: programmer error: kademlia responsibility unstarted", err.Error())
|
2018-08-01 13:57:37 +01:00
|
|
|
|
2018-11-16 16:31:14 +00:00
|
|
|
// run with nil, pass pointer to Kademlia in context
|
2018-11-27 17:46:12 +00:00
|
|
|
err = Config{}.Run(ctx, nil)
|
2018-11-16 16:31:14 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, "overlay error: database scheme not supported: ", err.Error())
|
2018-08-01 13:57:37 +01:00
|
|
|
|
2018-11-16 16:31:14 +00:00
|
|
|
// db scheme redis conn fail
|
2018-11-27 17:46:12 +00:00
|
|
|
err = Config{DatabaseURL: "redis://somedir/overlay.db/?db=1"}.Run(ctx, nil)
|
2018-08-01 13:57:37 +01:00
|
|
|
|
2018-11-16 16:31:14 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, "redis error: ping failed: dial tcp: address somedir: missing port in address", err.Error())
|
2018-08-01 13:57:37 +01:00
|
|
|
|
2018-11-16 16:31:14 +00:00
|
|
|
// db scheme bolt conn fail
|
2018-11-27 17:46:12 +00:00
|
|
|
err = Config{DatabaseURL: "bolt://somedir/overlay.db"}.Run(ctx, nil)
|
2018-11-16 16:31:14 +00:00
|
|
|
assert.Error(t, err)
|
2018-08-01 13:57:37 +01:00
|
|
|
}
|