forked from networkservicemesh/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework begin to simplify merge of Context
This is a simplification and rework in response to networkservicemesh#1234 Signed-off-by: Ed Warnicke <hagbard@gmail.com>
- Loading branch information
1 parent
8ddd0be
commit 9805c46
Showing
6 changed files
with
161 additions
and
52 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package begin_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/goleak" | ||
"google.golang.org/grpc" | ||
"google.golang.org/protobuf/proto" | ||
"google.golang.org/protobuf/types/known/emptypb" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/begin" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain" | ||
) | ||
|
||
func TestReRequestClient(t *testing.T) { | ||
t.Cleanup(func() { goleak.VerifyNone(t) }) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
client := chain.NewNetworkServiceClient( | ||
begin.NewClient(), | ||
) | ||
|
||
connOriginal, err := client.Request(ctx, &networkservice.NetworkServiceRequest{ | ||
Connection: &networkservice.Connection{ | ||
Id: "id", | ||
}, | ||
}) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, connOriginal) | ||
|
||
conn := connOriginal.Clone() | ||
conn.Context = &networkservice.ConnectionContext{ | ||
IpContext: &networkservice.IPContext{ | ||
SrcIpAddrs: []string{"10.0.0.1/32"}, | ||
}, | ||
EthernetContext: &networkservice.EthernetContext{ | ||
SrcMac: "00:00:00:00:00:00", | ||
}, | ||
DnsContext: &networkservice.DNSContext{ | ||
Configs: []*networkservice.DNSConfig{ | ||
{ | ||
DnsServerIps: []string{"1.1.1.1"}, | ||
}, | ||
}, | ||
}, | ||
ExtraContext: map[string]string{"foo": "bar"}, | ||
} | ||
conn.Mechanism = kernel.New("") | ||
conn.Labels = map[string]string{"foo": "bar"} | ||
|
||
connReturned, err := client.Request(ctx, &networkservice.NetworkServiceRequest{ | ||
Connection: conn, | ||
}) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, connReturned) | ||
require.Equal(t, connOriginal.GetMechanism(), connReturned.GetMechanism()) | ||
require.True(t, proto.Equal(conn.GetContext(), connReturned.GetContext())) | ||
require.Equal(t, connOriginal.GetLabels(), connReturned.GetLabels()) | ||
} | ||
|
||
type reRequestClient struct{} | ||
|
||
func newReRequestClient() networkservice.NetworkServiceClient { | ||
return &reRequestClient{} | ||
} | ||
|
||
func (r *reRequestClient) Request(ctx context.Context, in *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (r *reRequestClient) Close(ctx context.Context, in *networkservice.Connection, opts ...grpc.CallOption) (*emptypb.Empty, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
var _ networkservice.NetworkServiceClient = &reRequestClient{} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dial_test | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"testing" | ||
"time" | ||
|
||
"google.golang.org/grpc" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
) | ||
|
||
func TestDial(t *testing.T) { | ||
var dialer net.Dialer | ||
conn, err := dialer.DialContext(context.Background(), "tcp", "142.251.1.106:53") | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
if conn == nil { | ||
panic(conn) | ||
} | ||
} | ||
|
||
func TestDial2(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond) | ||
defer cancel() | ||
cc, err := grpc.DialContext(ctx, "142.251.1.106:53", grpc.WithInsecure(), grpc.WithBlock()) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
if cc == nil { | ||
panic(cc) | ||
} | ||
client := networkservice.NewNetworkServiceClient(cc) | ||
conn, err := client.Request(context.Background(), &networkservice.NetworkServiceRequest{}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
if conn == nil { | ||
panic(cc) | ||
} | ||
} |