2018-06-22 14:33:57 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package overlay
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/kademlia"
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-06-22 14:33:57 +01:00
|
|
|
"storj.io/storj/storage"
|
2018-09-11 08:27:12 +01:00
|
|
|
"storj.io/storj/storage/teststore"
|
2018-06-22 14:33:57 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewMockServer provides a mock grpc server for testing
|
2018-10-19 15:05:31 +01:00
|
|
|
func NewMockServer(items []storage.ListItem, opts ...grpc.ServerOption) *grpc.Server {
|
|
|
|
grpcServer := grpc.NewServer(opts...)
|
2018-06-22 14:33:57 +01:00
|
|
|
|
|
|
|
registry := monkit.Default
|
|
|
|
|
|
|
|
k := kademlia.NewMockKademlia()
|
|
|
|
|
|
|
|
c := &Cache{
|
2018-09-11 08:27:12 +01:00
|
|
|
DB: teststore.New(),
|
2018-06-22 14:33:57 +01:00
|
|
|
DHT: k,
|
|
|
|
}
|
|
|
|
|
2018-09-11 08:27:12 +01:00
|
|
|
_ = storage.PutAll(c.DB, items...)
|
|
|
|
|
2018-06-22 14:33:57 +01:00
|
|
|
s := Server{
|
|
|
|
dht: k,
|
|
|
|
cache: c,
|
|
|
|
logger: zap.NewNop(),
|
|
|
|
metrics: registry,
|
|
|
|
}
|
2018-09-18 05:39:06 +01:00
|
|
|
pb.RegisterOverlayServer(grpcServer, &s)
|
2018-06-22 14:33:57 +01:00
|
|
|
|
|
|
|
return grpcServer
|
|
|
|
}
|