storj/pkg/overlay/service_test.go
Dennis Coyle a5ff5016c9
pkg/kademlia tests and restructuring (#97)
* port changes

* Merge remote-tracking branch 'upstream/master'

* Merge remote-tracking branch 'upstream/master'

* Merge remote-tracking branch 'upstream/master'

* files created

* Merge remote-tracking branch 'upstream/master' into coyle/kad-tests

* wip

* Merge remote-tracking branch 'upstream/master' into coyle/kad-tests

* wip

* remove bkad dependencie from tests

* wip

* wip

* wip

* wip

* wip

* updated coyle/kademlia

* wip

* cleanup

* ports

* overlay upgraded

* linter fixes

* piecestore kademlia newID

* add changes from kad demo

* PR comments addresses

* go func

* force travis build

* fixed merge conflicts

* fixed merge conflicts

* Merge branch 'coyle/kad-tests' of https://github.com/coyle/storj into coyle/kad-tests

* linter issues

* linting issues

* fixed merge conflicts

* linter is stupid
2018-06-22 09:33:57 -04:00

75 lines
1.6 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package overlay
import (
"context"
"flag"
"log"
"os"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/zeebo/errs"
"go.uber.org/zap"
"gopkg.in/spacemonkeygo/monkit.v2"
"storj.io/storj/internal/test"
"storj.io/storj/pkg/process"
// naming proto to avoid confusion with this package
)
func newTestService(t *testing.T) Service {
return Service{
logger: zap.NewNop(),
metrics: monkit.Default,
}
}
func TestProcess_redis(t *testing.T) {
flag.Set("localPort", "0")
done := test.EnsureRedis(t)
defer done()
o := newTestService(t)
ctx, _ := context.WithTimeout(context.Background(), 500*time.Millisecond)
err := o.Process(ctx)
assert.NoError(t, err)
}
func TestProcess_bolt(t *testing.T) {
flag.Set("localPort", "0")
flag.Set("redisAddress", "")
boltdbPath, err := filepath.Abs("test_bolt.db")
assert.NoError(t, err)
if err != nil {
defer func() {
if err := os.Remove(boltdbPath); err != nil {
log.Println(errs.New("error while removing test bolt db: %s", err))
}
}()
}
flag.Set("boltdbPath", boltdbPath)
o := newTestService(t)
ctx, _ := context.WithTimeout(context.Background(), 500*time.Millisecond)
err = o.Process(ctx)
assert.NoError(t, err)
}
func TestProcess_error(t *testing.T) {
flag.Set("localPort", "0")
flag.Set("boltdbPath", "")
flag.Set("redisAddress", "")
o := newTestService(t)
ctx, _ := context.WithTimeout(context.Background(), 500*time.Millisecond)
err := o.Process(ctx)
assert.True(t, process.ErrUsage.Has(err))
}