MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / TestIPList_Contains

Function TestIPList_Contains

internal/iplibrary/ip_list_test.go:181–222  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

179}
180
181func TestIPList_Contains(t *testing.T) {
182 var a = assert.NewAssertion(t)
183
184 var list = iplibrary.NewIPList()
185 for i := 0; i < 255; i++ {
186 list.Add(&iplibrary.IPItem{
187 Id: uint64(i),
188 IPFrom: iputils.ToBytes(strconv.Itoa(i) + ".168.0.1"),
189 IPTo: iputils.ToBytes(strconv.Itoa(i) + ".168.255.1"),
190 ExpiredAt: 0,
191 })
192 }
193 for i := 0; i < 255; i++ {
194 list.Add(&iplibrary.IPItem{
195 Id: uint64(1000 + i),
196 IPFrom: iputils.ToBytes("192.167.2." + strconv.Itoa(i)),
197 })
198 }
199
200 list.Add(&iplibrary.IPItem{
201 Id: 10000,
202 IPFrom: iputils.ToBytes("::1"),
203 })
204 list.Add(&iplibrary.IPItem{
205 Id: 10001,
206 IPFrom: iputils.ToBytes("::2"),
207 IPTo: iputils.ToBytes("::5"),
208 })
209
210 t.Log(len(list.ItemsMap()), "ip")
211
212 var before = time.Now()
213 a.IsTrue(list.Contains(iputils.ToBytes("192.168.1.100")))
214 a.IsTrue(list.Contains(iputils.ToBytes("192.168.2.100")))
215 a.IsFalse(list.Contains(iputils.ToBytes("192.169.3.100")))
216 a.IsFalse(list.Contains(iputils.ToBytes("192.167.3.100")))
217 a.IsTrue(list.Contains(iputils.ToBytes("192.167.2.100")))
218 a.IsTrue(list.Contains(iputils.ToBytes("::1")))
219 a.IsTrue(list.Contains(iputils.ToBytes("::3")))
220 a.IsFalse(list.Contains(iputils.ToBytes("::8")))
221 t.Log(time.Since(before).Seconds()*1000, "ms")
222}
223
224func TestIPList_Contains_Many(t *testing.T) {
225 var list = iplibrary.NewIPList()

Callers

nothing calls this directly

Calls 5

NewIPListFunction · 0.92
LogMethod · 0.80
AddMethod · 0.65
ItemsMapMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected