Skip to content

Commit

Permalink
fix unstable test (would fail due to dns result sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
dropwhile committed Oct 23, 2023
1 parent 9d4831e commit a48538a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/camo/upstream_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ package camo
import (
"fmt"
"net"
"sort"
"testing"

"golang.org/x/net/http/httpproxy"
"gotest.tools/v3/assert"
)

func IPListToStringList(sliceList []net.IP) []string {
list := make([]string, 0, len(sliceList))
for _, item := range sliceList {
list = append(list, item.String())
}
return list
}

func TestUpstreamProxyParsing(t *testing.T) {
t.Parallel()

Expand All @@ -38,12 +47,15 @@ func TestUpstreamProxyParsing(t *testing.T) {
assert.Equal(t, uspc.httpsProxy.scheme, "socks5")
assert.Equal(t, uspc.httpsProxy.host, "localhost")
assert.Equal(t, uspc.httpsProxy.port, "9999")

addresses := IPListToStringList(uspc.httpsProxy.addresses)
sort.Strings(addresses)
assert.DeepEqual(
t,
uspc.httpsProxy.addresses,
[]net.IP{
net.ParseIP("127.0.0.1"),
net.ParseIP("::1"),
addresses,
[]string{
"127.0.0.1",
"::1",
},
)
}
Expand Down Expand Up @@ -128,5 +140,4 @@ func TestUpstreamProxyMatching(t *testing.T) {
errMsg(elem.matchtype, elem.address, elem.port, elem.result),
)
}

}

0 comments on commit a48538a

Please sign in to comment.