-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathresult_test.go
More file actions
49 lines (39 loc) · 996 Bytes
/
Copy pathresult_test.go
File metadata and controls
49 lines (39 loc) · 996 Bytes
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
43
44
45
46
47
48
49
package maxminddb
import (
"net/netip"
"testing"
"github.com/stretchr/testify/assert"
)
var benchmarkFoundSink bool
func BenchmarkResultFound(b *testing.B) {
result := Result{reader: &Reader{}, offset: 1}
for b.Loop() {
benchmarkFoundSink = result.Found()
}
}
func TestResultPrefixUsesIPv4StartBitDepth(t *testing.T) {
reader := &Reader{
Metadata: Metadata{IPVersion: 6, NodeCount: 8},
ipv4Start: 4,
ipv4StartBitDepth: 64,
}
result := Result{
reader: reader,
ip: netip.MustParseAddr("1.2.3.4"),
prefixLen: 88,
}
assert.Equal(t, "1.2.3.0/24", result.Prefix().String())
}
func TestResultPrefixReturnsIPv6NetworkWithoutIPv4Subtree(t *testing.T) {
reader := &Reader{
Metadata: Metadata{IPVersion: 6, NodeCount: 8},
ipv4Start: 8,
ipv4StartBitDepth: 64,
}
result := Result{
reader: reader,
ip: netip.MustParseAddr("1.2.3.4"),
prefixLen: 64,
}
assert.Equal(t, "::/64", result.Prefix().String())
}