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.
Revert "Revert authorize changes (networkservicemesh#1645)"
This reverts commit bf440a3.
- Loading branch information
1 parent
34ab19f
commit dc986df
Showing
5 changed files
with
149 additions
and
2 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
59 changes: 59 additions & 0 deletions
59
pkg/networkservice/utils/checks/checkcontextonreturn/server.go
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,59 @@ | ||
// Copyright (c) 2020-2024 Cisco and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package checkcontextonreturn - provides a NetworkServiceClient chain element for checking the state of the context.Context | ||
// | ||
// after the next element in the chain has returned | ||
package checkcontextonreturn | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/golang/protobuf/ptypes/empty" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next" | ||
) | ||
|
||
type checkContextOnReturnServer struct { | ||
*testing.T | ||
check func(t *testing.T, ctx context.Context) | ||
} | ||
|
||
// NewServer - returns a NetworkServiceServer chain element for checking the state of the context.Context | ||
// | ||
// after the next element in the chain has returned | ||
// t - *testing.T for doing the checks | ||
// check - function for checking the context.Context | ||
func NewServer(t *testing.T, check func(t *testing.T, ctx context.Context)) networkservice.NetworkServiceServer { | ||
return &checkContextOnReturnServer{ | ||
T: t, | ||
check: check, | ||
} | ||
} | ||
|
||
func (t *checkContextOnReturnServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { | ||
conn, err := next.Server(ctx).Request(ctx, request) | ||
t.check(t.T, ctx) | ||
return conn, err | ||
} | ||
|
||
func (t *checkContextOnReturnServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { | ||
e, err := next.Server(ctx).Close(ctx, conn) | ||
t.check(t.T, ctx) | ||
return e, err | ||
} |