From c1aa9e6984243f599ef8a0df7172b011b6f4d0b8 Mon Sep 17 00:00:00 2001 From: Vladimir Popov Date: Mon, 5 Apr 2021 21:57:26 +0700 Subject: [PATCH] Add clockmock sandbox test Signed-off-by: Vladimir Popov --- pkg/tools/clockmock/mock_test.go | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/pkg/tools/clockmock/mock_test.go b/pkg/tools/clockmock/mock_test.go index 3e588530cd..9316bbfaf2 100644 --- a/pkg/tools/clockmock/mock_test.go +++ b/pkg/tools/clockmock/mock_test.go @@ -22,10 +22,16 @@ import ( "testing" "time" + "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls" + kernelmech "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel" + "github.com/networkservicemesh/api/pkg/api/registry" "github.com/stretchr/testify/require" "go.uber.org/goleak" + "github.com/networkservicemesh/sdk/pkg/tools/clock" "github.com/networkservicemesh/sdk/pkg/tools/clockmock" + "github.com/networkservicemesh/sdk/pkg/tools/sandbox" ) const ( @@ -354,3 +360,60 @@ func TestMock_WithTimeout(t *testing.T) { require.FailNow(t, "too late") } } + +func TestMock_Sandbox(t *testing.T) { + t.Cleanup(func() { goleak.VerifyNone(t) }) + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + m := clockmock.New() + ctx = clock.WithClock(ctx, m) + + domain := sandbox.NewBuilder(ctx, t). + SetNodesCount(1). + SetNSMgrProxySupplier(nil). + SetRegistryProxySupplier(nil). + Build() + + nsReg, err := domain.Nodes[0].NSRegistryClient.Register(ctx, ®istry.NetworkService{ + Name: "ns", + }) + require.NoError(t, err) + + nseReg := ®istry.NetworkServiceEndpoint{ + Name: "nse", + NetworkServiceNames: []string{nsReg.Name}, + } + + domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken) + + nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken) + + request := &networkservice.NetworkServiceRequest{ + MechanismPreferences: []*networkservice.Mechanism{ + {Cls: cls.LOCAL, Type: kernelmech.MECHANISM}, + }, + Connection: &networkservice.Connection{ + Id: "1", + NetworkService: nsReg.Name, + Context: &networkservice.ConnectionContext{}, + }, + } + + conn, err := nsc.Request(ctx, request.Clone()) + require.NoError(t, err) + + // Simulate refresh from client. + + refreshRequest := request.Clone() + refreshRequest.Connection = conn.Clone() + + conn, err = nsc.Request(ctx, refreshRequest) + require.NoError(t, err) + + // Close. + + _, err = nsc.Close(ctx, conn) + require.NoError(t, err) +}