Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce interface translation #457

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions util/eos/eos_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package eos_util

import "strings"

// TranslateEosInterface returns a kernel interface name from an EOS interface eosInterfaceName
// e.g. Management1/1 to ma1_1
func TranslateEosInterface(eosInterfaceName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have reverse direction mapping too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave that for a later time tbh

kernelName := strings.ReplaceAll(eosInterfaceName, "Ethernet", "et")
kernelName = strings.ReplaceAll(kernelName, "Management", "ma")
kernelName = strings.ReplaceAll(kernelName, "/", "_")
return kernelName
}
31 changes: 31 additions & 0 deletions util/eos/eos_util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package eos_util

import (
"testing"
)

func TestRandomizeSlice(t *testing.T) {
tests := []struct {
eosName string
kernelName string
}{
{
eosName: "Ethernet1/4",
kernelName: "et1_4",
},
{
eosName: "Management1/1",
kernelName: "ma1_1",
},
}

// setting custom seed wua Seed has been deprecated

for _, test := range tests {
t.Run(test.eosName, func(t *testing.T) {
if kernelName := TranslateEosInterface(test.eosName); kernelName != test.kernelName {
t.Errorf("Expected %s -- got %s", test.kernelName, kernelName)
}
})
}
}
2 changes: 1 addition & 1 deletion util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestRandomizeSlice(t *testing.T) {
},
}

// setting custom seed wua Seed has been depricated
// setting custom seed wua Seed has been deprecated

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down