From 842910540749ea4956b42c7b289026800d3b41ab Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 26 Jan 2021 23:24:42 -0800 Subject: [PATCH] Add regression test for #125. Signed-off-by: David Anderson --- ipset_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ipset_test.go b/ipset_test.go index a06cc27..c80f2b8 100644 --- a/ipset_test.go +++ b/ipset_test.go @@ -210,6 +210,22 @@ func TestIPSet(t *testing.T) { }, wantPrefixes: pxv("10.0.0.0/30", "10.0.0.255/32"), }, + { + // regression test for a bug where Ranges returned invalid IPRanges. + name: "single_ip_removal", + f: func(s *IPSet) { + s.Add(mustIP("10.0.0.0")) + s.Add(mustIP("10.0.0.1")) + s.Add(mustIP("10.0.0.2")) + s.Add(mustIP("10.0.0.3")) + s.Add(mustIP("10.0.0.4")) + s.Remove(mustIP("10.0.0.4")) + }, + wantRanges: []IPRange{ + {mustIP("10.0.0.0"), mustIP("10.0.0.3")}, + }, + wantPrefixes: pxv("10.0.0.0/30"), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -220,6 +236,7 @@ func TestIPSet(t *testing.T) { got := s.Ranges() t.Run("ranges", func(t *testing.T) { for _, v := range got { + debugf("%s -> %s", v.From, v.To) if !v.Valid() { t.Errorf("invalid IPRange in result: %s -> %s", v.From, v.To) }