From a038a201bda29599e5131f15a742301ad3504ab4 Mon Sep 17 00:00:00 2001 From: NikitaSkrynnik Date: Tue, 12 Mar 2024 18:09:27 +0700 Subject: [PATCH] cleanup + fix some tests Signed-off-by: NikitaSkrynnik --- pkg/networkservice/common/mechanisms/kernel/client.go | 2 +- .../common/mechanisms/kernel/client_test.go | 3 +-- .../common/mechanismtranslation/client_test.go | 10 +++++++--- pkg/tools/nanoid/generator.go | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/networkservice/common/mechanisms/kernel/client.go b/pkg/networkservice/common/mechanisms/kernel/client.go index a1f6823d5..6a67022c4 100644 --- a/pkg/networkservice/common/mechanisms/kernel/client.go +++ b/pkg/networkservice/common/mechanisms/kernel/client.go @@ -53,7 +53,7 @@ func (k *kernelMechanismClient) Request(ctx context.Context, request *networkser if err != nil { return nil, errors.Wrap(err, "Failed to update mechanism preferences") } - if updated { + if !updated { mechanism := kernelmech.ToMechanism(kernelmech.New(netNSURL)) if k.interfaceName != "" { mechanism.SetInterfaceName(k.interfaceName) diff --git a/pkg/networkservice/common/mechanisms/kernel/client_test.go b/pkg/networkservice/common/mechanisms/kernel/client_test.go index 540a9a776..0b91c8b26 100644 --- a/pkg/networkservice/common/mechanisms/kernel/client_test.go +++ b/pkg/networkservice/common/mechanisms/kernel/client_test.go @@ -90,7 +90,6 @@ func TestKernelMechanismClient_ShouldSetRandomInteraceName(t *testing.T) { require.Len(t, ifname, kernelmech.LinuxIfMaxLength) require.True(t, strings.HasPrefix(ifname, "nsm")) for i := 0; i < kernelmech.LinuxIfMaxLength; i++ { - require.Contains(t, nanoid.DefaultAlphabet, ifname[i]) + require.Contains(t, nanoid.DefaultAlphabet, string(ifname[i])) } - require.Equal(t, netNSURL, req.MechanismPreferences[0].Parameters[kernelmech.NetNSURL]) } diff --git a/pkg/networkservice/common/mechanismtranslation/client_test.go b/pkg/networkservice/common/mechanismtranslation/client_test.go index efa39e950..1c413dc67 100644 --- a/pkg/networkservice/common/mechanismtranslation/client_test.go +++ b/pkg/networkservice/common/mechanismtranslation/client_test.go @@ -41,13 +41,17 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" ) +const ( + clientIfName = "nsm1" +) + func kernelMechanism() *networkservice.Mechanism { request := &networkservice.NetworkServiceRequest{ Connection: &networkservice.Connection{ Id: "id", }, } - _, _ = kernel.NewClient().Request(context.Background(), request) + _, _ = kernel.NewClient(kernel.WithInterfaceName(clientIfName)).Request(context.Background(), request) return request.MechanismPreferences[0] } @@ -58,7 +62,7 @@ func TestMechanismTranslationClient(t *testing.T) { metadata.NewClient(), mechanismtranslation.NewClient(), capture, - kernel.NewClient(), + kernel.NewClient(kernel.WithInterfaceName(clientIfName)), adapters.NewServerToClient( mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{ kernelmech.MECHANISM: null.NewServer(), @@ -130,7 +134,7 @@ func TestMechanismTranslationClient_CloseOnError(t *testing.T) { } count++ }), - kernel.NewClient(), + kernel.NewClient(kernel.WithInterfaceName(clientIfName)), adapters.NewServerToClient( mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{ kernelmech.MECHANISM: null.NewServer(), diff --git a/pkg/tools/nanoid/generator.go b/pkg/tools/nanoid/generator.go index 17b1a97e4..a2252a70d 100644 --- a/pkg/tools/nanoid/generator.go +++ b/pkg/tools/nanoid/generator.go @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package nanoid is a tiny, unique string ID generator +// Package nanoid is a tiny, unique string ID generator. Original JavaScript implementaion: https://github.com/ai/nanoid package nanoid import (