File: 0001-Fix-sort-test.patch

package info (click to toggle)
golang-github-hashicorp-go-sockaddr 1.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 680 kB
  • sloc: makefile: 4
file content (42 lines) | stat: -rw-r--r-- 1,261 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
From: Shengjing Zhu <zhsj@debian.org>
Date: Sun, 21 Aug 2022 22:43:58 +0800
Subject: Fix sort test

---
 ifaddrs_test.go | 4 ++--
 ipaddrs.go      | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/ifaddrs_test.go b/ifaddrs_test.go
index c89af4a..4d12e35 100644
--- a/ifaddrs_test.go
+++ b/ifaddrs_test.go
@@ -780,8 +780,8 @@ func TestGetAllInterfaces(t *testing.T) {
 	}
 
 	for i := initialLen - 1; i >= 0; i-- {
-		if !reflect.DeepEqual(descSorted[i], ifAddrs[i]) {
-			t.Errorf("wrong sort order: %d %v %v", i, descSorted[i], ifAddrs[i])
+		if !reflect.DeepEqual(ascSorted[i], ifAddrs[i]) {
+			t.Errorf("wrong sort order: %d %v %v", i, ascSorted[i], ifAddrs[i])
 		}
 	}
 }
diff --git a/ipaddrs.go b/ipaddrs.go
index 6eeb7dd..c8ef6e6 100644
--- a/ipaddrs.go
+++ b/ipaddrs.go
@@ -67,9 +67,12 @@ func (s SortIPAddrsByNetworkSize) Less(i, j int) bool {
 	// that have a port (e.g. a host with a /32 and port number is more
 	// specific and should sort first over a host with a /32 but no port
 	// set).
-	if s.IPAddrs[i].IPPort() == 0 || s.IPAddrs[j].IPPort() == 0 {
+	if s.IPAddrs[i].IPPort() == 0 {
 		return false
 	}
+	if s.IPAddrs[j].IPPort() == 0 {
+		return true
+	}
 	return s.IPAddrs[i].IPPort() < s.IPAddrs[j].IPPort()
 }