Skip to content

Commit

Permalink
cleanup + fix some tests
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Mar 12, 2024
1 parent bf3a93f commit a038a20
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/networkservice/common/mechanisms/kernel/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Check warning on line 55 in pkg/networkservice/common/mechanisms/kernel/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/networkservice/common/mechanisms/kernel/client.go#L54-L55

Added lines #L54 - L55 were not covered by tests
if updated {
if !updated {
mechanism := kernelmech.ToMechanism(kernelmech.New(netNSURL))
if k.interfaceName != "" {
mechanism.SetInterfaceName(k.interfaceName)
Expand Down
3 changes: 1 addition & 2 deletions pkg/networkservice/common/mechanisms/kernel/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
10 changes: 7 additions & 3 deletions pkg/networkservice/common/mechanismtranslation/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/tools/nanoid/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit a038a20

Please sign in to comment.