-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2231 from katiewasnothere/kabaldau/sort_endpoints
Sort the endpoints such that eth0 is first
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//go:build windows | ||
|
||
package uvm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/Microsoft/hcsshim/internal/hns" | ||
) | ||
|
||
func Test_SortEndpoints(t *testing.T) { | ||
type config struct { | ||
endpointNames []string | ||
targetName string | ||
} | ||
tests := []config{ | ||
{ | ||
endpointNames: []string{"eth1", "eth0"}, | ||
targetName: "eth0", | ||
}, | ||
{ | ||
endpointNames: []string{"eth0", "eth1"}, | ||
targetName: "eth0", | ||
}, | ||
{ | ||
endpointNames: []string{"eth1", "name-eth0"}, | ||
targetName: "name-eth0", | ||
}, | ||
{ | ||
endpointNames: []string{"name-eth098", "name-eth0"}, | ||
targetName: "name-eth0", | ||
}, | ||
{ | ||
endpointNames: []string{"name-eth0", "name-eth098"}, | ||
targetName: "name-eth0", | ||
}, | ||
{ | ||
endpointNames: []string{"random-ifname", "another-random-ifname"}, | ||
// ordering shouldn't change so the first entry should still be first | ||
targetName: "random-ifname", | ||
}, | ||
{ | ||
endpointNames: []string{"eth0-name", "name-eth0"}, | ||
targetName: "name-eth0", | ||
}, | ||
{ | ||
endpointNames: []string{}, | ||
}, | ||
} | ||
for i, test := range tests { | ||
t.Run(fmt.Sprint(t.Name(), i), func(st *testing.T) { | ||
endpoints := []*hns.HNSEndpoint{} | ||
for _, n := range test.endpointNames { | ||
e := &hns.HNSEndpoint{ | ||
Name: n, | ||
} | ||
endpoints = append(endpoints, e) | ||
} | ||
|
||
sortEndpoints(endpoints) | ||
if len(test.endpointNames) != 0 { | ||
if endpoints[0].Name != test.targetName { | ||
st.Fatalf("expected endpoint sorting to return endpoint with name %s first, instead got %s", test.targetName, endpoints[0].Name) | ||
} | ||
} | ||
}) | ||
} | ||
} |