-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Artem Glazychev <[email protected]>
- Loading branch information
1 parent
dbbea17
commit 36b7c01
Showing
6 changed files
with
15 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,148 +18,10 @@ | |
package testutil | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/golang/protobuf/ptypes/empty" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next" | ||
) | ||
|
||
// NewConnection - create connection for testing | ||
func NewConnection() *networkservice.NetworkServiceRequest { | ||
return &networkservice.NetworkServiceRequest{ | ||
Connection: &networkservice.Connection{ | ||
Id: "conn-1", | ||
Context: &networkservice.ConnectionContext{ | ||
IpContext: &networkservice.IPContext{ | ||
SrcIpRequired: true, | ||
}, | ||
}, | ||
}, | ||
MechanismPreferences: []*networkservice.Mechanism{ | ||
{ | ||
Type: "KERNEL", | ||
Cls: cls.LOCAL, | ||
}, | ||
{ | ||
Type: "KERNEL", | ||
Cls: cls.LOCAL, | ||
Parameters: map[string]string{ | ||
"label": "v2", | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// LabelChangerFirstServer - common server for testing | ||
type LabelChangerFirstServer struct{} | ||
|
||
// Request - test request | ||
func (c *LabelChangerFirstServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { | ||
request.Connection.Labels = map[string]string{ | ||
"Label": "A", | ||
} | ||
rv, err := next.Server(ctx).Request(ctx, request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
rv.Labels = map[string]string{ | ||
"Label": "D", | ||
} | ||
return rv, err | ||
} | ||
|
||
// Close - test request | ||
func (c *LabelChangerFirstServer) Close(ctx context.Context, connection *networkservice.Connection) (*empty.Empty, error) { | ||
connection.Labels = map[string]string{ | ||
"Label": "W", | ||
} | ||
r, err := next.Server(ctx).Close(ctx, connection) | ||
connection.Labels = map[string]string{ | ||
"Label": "Z", | ||
} | ||
return r, err | ||
} | ||
|
||
// LabelChangerSecondServer - common server for testing | ||
type LabelChangerSecondServer struct{} | ||
|
||
// Request - test request | ||
func (c *LabelChangerSecondServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { | ||
request.Connection.Labels = map[string]string{ | ||
"Label": "B", | ||
} | ||
rv, err := next.Server(ctx).Request(ctx, request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
rv.Labels = map[string]string{ | ||
"Label": "C", | ||
} | ||
return rv, err | ||
} | ||
|
||
// Close - test request | ||
func (c *LabelChangerSecondServer) Close(ctx context.Context, connection *networkservice.Connection) (*empty.Empty, error) { | ||
connection.Labels = map[string]string{ | ||
"Label": "X", | ||
} | ||
r, err := next.Server(ctx).Close(ctx, connection) | ||
connection.Labels = map[string]string{ | ||
"Label": "Y", | ||
} | ||
return r, err | ||
} | ||
|
||
// CustomError - custom error for testing | ||
type CustomError struct{} | ||
|
||
// Error - error message example | ||
func (*CustomError) Error() string { | ||
return `Error returned from api/pkg/api/networkservice/networkServiceClient.Close | ||
github.com/networkservicemesh/sdk/pkg/networkservice/core/trace.(*beginTraceClient).Close | ||
/root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/trace/client.go:85 | ||
github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close | ||
/root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65 | ||
github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close | ||
/root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65 | ||
github.com/networkservicemesh/sdk/pkg/networkservice/core/trace.(*endTraceClient).Close | ||
/root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/trace/client.go:106 | ||
github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close | ||
/root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65` | ||
} | ||
|
||
// StackTrace - testing errors utility | ||
func (*CustomError) StackTrace() errors.StackTrace { | ||
return []errors.Frame{} | ||
} | ||
|
||
// ErrorServer - error server for testing | ||
type ErrorServer struct{} | ||
|
||
// Request - test request | ||
func (c *ErrorServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { | ||
request.Connection.Labels = map[string]string{ | ||
"Label": "B", | ||
} | ||
|
||
_, _ = next.Server(ctx).Request(ctx, request) | ||
|
||
return nil, &CustomError{} | ||
} | ||
|
||
// Close - test request | ||
func (c *ErrorServer) Close(ctx context.Context, connection *networkservice.Connection) (*empty.Empty, error) { | ||
return next.Server(ctx).Close(ctx, connection) | ||
} | ||
|
||
// TrimLogTime - to format logs | ||
func TrimLogTime(buff fmt.Stringer) string { | ||
// Logger created by the trace chain element uses custom formatter, which prints date and time info in each line | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters