-
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 ba512e4
Showing
7 changed files
with
16 additions
and
149 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
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