Skip to content

Commit

Permalink
Move injecterror from utils/ to utils/inject/injecterror
Browse files Browse the repository at this point in the history
Signed-off-by: Ed Warnicke <hagbard@gmail.com>
  • Loading branch information
edwarnicke committed Feb 23, 2020
1 parent 604e5fb commit 46e4c77
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/networkservice/common/mechanisms/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/injecterror"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/inject/injecterror"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/null"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,31 @@ import (
"google.golang.org/grpc"
)

type testErrorClient struct{}
type injectErrorClient struct{
err *error
}

// NewClient - returns a testerror client that always returns an error when calling Request/Close
func NewClient() networkservice.NetworkServiceClient {
return &testErrorClient{}
func NewClient(errs... error) networkservice.NetworkServiceClient {
var err *error
if len(errs) >0 {
err = &(errs[0])
}
return &injectErrorClient{
err:err,
}
}

func (e *testErrorClient) Request(ctx context.Context, in *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
return nil, errors.New("error originates in testErrorClient")
func (e *injectErrorClient) Request(ctx context.Context, in *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
if e.err != nil {
return nil,*(e.err)
}
return nil, errors.New("error originates in injectErrorClient")
}

func (e *testErrorClient) Close(ctx context.Context, in *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
return &empty.Empty{}, errors.New("error originates in testErrorClient")
func (e *injectErrorClient) Close(ctx context.Context, in *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
if e.err != nil {
return &empty.Empty{},*(e.err)
}
return &empty.Empty{}, errors.New("error originates in injectErrorClient")
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,31 @@ import (
"github.com/pkg/errors"
)

type testErrorServer struct{}
type injectErrorServer struct{
err *error
}

// NewServer - returns a testerror server that always returns an error when calling Request/Close
func NewServer() networkservice.NetworkServiceServer {
return &testErrorServer{}
func NewServer(errs... error) networkservice.NetworkServiceServer {
var err *error
if len(errs) >0 {
err = &errs[0]
}
return &injectErrorServer{
err: err,
}
}

func (e testErrorServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
return nil, errors.New("error originated in testErrorServer")
func (e injectErrorServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
if e.err != nil {
return nil,*(e.err)
}
return nil, errors.New("error originated in injectErrorServer")
}

func (e testErrorServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) {
return &empty.Empty{}, errors.New("error originated in testErrorServer")
func (e injectErrorServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) {
if e.err != nil {
return &empty.Empty{},*(e.err)
}
return &empty.Empty{}, errors.New("error originated in injectErrorServer")
}

0 comments on commit 46e4c77

Please sign in to comment.