storj/pkg/overlay/config_test.go

39 lines
993 B
Go
Raw Normal View History

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package overlay
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"storj.io/storj/pkg/kademlia"
)
func TestRun(t *testing.T) {
bctx := context.Background()
kad := &kademlia.Kademlia{}
2018-11-16 16:31:14 +00:00
var kadKey kademlia.CtxKey
ctx := context.WithValue(bctx, kadKey, kad)
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-11-16 16:31:14 +00:00
// run with nil, pass pointer to Kademlia in context
err = Config{}.Run(ctx, nil)
2018-11-16 16:31:14 +00:00
assert.Error(t, err)
assert.Equal(t, "overlay error: unable to get master db instance", err.Error())
2018-11-16 16:31:14 +00:00
// db scheme redis conn fail
err = Config{DatabaseURL: "redis://somedir/overlay.db/?db=1"}.Run(ctx, nil)
2018-11-16 16:31:14 +00:00
assert.Error(t, err)
2018-11-16 16:31:14 +00:00
// db scheme bolt conn fail
err = Config{DatabaseURL: "bolt://somedir/overlay.db"}.Run(ctx, nil)
2018-11-16 16:31:14 +00:00
assert.Error(t, err)
}