storj/pkg/overlay/service_test.go

75 lines
1.6 KiB
Go
Raw Normal View History

// 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))
}