Skip to content

Commit

Permalink
Run golines
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Sep 4, 2024
1 parent 6c6cdb0 commit 9b7645c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 21 deletions.
12 changes: 9 additions & 3 deletions mmdbtype/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ func makeTestStrings() map[string]DataType {
"40": String(""),
"4131": String("1"),
"43e4baba": String("人"),
"5b313233343536373839303132333435363738393031323334353637": String("123456789012345678901234567"),
"5c31323334353637383930313233343536373839303132333435363738": String("1234567890123456789012345678"),
"5d003132333435363738393031323334353637383930313233343536373839": String("12345678901234567890123456789"),
"5b313233343536373839303132333435363738393031323334353637": String(
"123456789012345678901234567",
),
"5c31323334353637383930313233343536373839303132333435363738": String(
"1234567890123456789012345678",
),
"5d003132333435363738393031323334353637383930313233343536373839": String(
"12345678901234567890123456789",
),
"5d01313233343536373839303132333435363738393031323334353637383930": String(
"123456789012345678901234567890"),
}
Expand Down
71 changes: 53 additions & 18 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,22 +418,28 @@ func TestTreeInsertAndGet(t *testing.T) {
network: "1.1.0.0/24",
start: "1.1.0.0",
end: "1.1.0.255",
value: mmdbtype.Map{"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}}},
value: mmdbtype.Map{
"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}},
},
},
{
network: "1.1.1.0/24",
start: "1.1.1.0",
end: "1.1.1.255",
// We intentionally don't use the same variable for
// here and above as we want them to be different instances.
value: mmdbtype.Map{"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}}},
value: mmdbtype.Map{
"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}},
},
},
},
gets: []testGet{
{
ip: "1.1.0.0",
expectedNetwork: "1.1.0.0/23",
expectedGetValue: mmdbtype.Map{"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}}},
ip: "1.1.0.0",
expectedNetwork: "1.1.0.0/23",
expectedGetValue: mmdbtype.Map{
"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}},
},
expectedLookupValue: func() *any {
v := any(map[string]any{"a": []any{uint64(1), []byte{1, 2}}})
return &v
Expand All @@ -449,22 +455,28 @@ func TestTreeInsertAndGet(t *testing.T) {
network: "1.1.0.0/24",
start: "1.1.0.0",
end: "1.1.0.255",
value: mmdbtype.Map{"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}}},
value: mmdbtype.Map{
"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}},
},
},
{
network: "1.1.0.128/26",
start: "1.1.0.128",
end: "1.1.0.191",
// We intentionally don't use the same variable for
// here and above as we want them to be different instances.
value: mmdbtype.Map{"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}}},
value: mmdbtype.Map{
"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}},
},
},
},
gets: []testGet{
{
ip: "1.1.0.0",
expectedNetwork: "1.1.0.0/24",
expectedGetValue: mmdbtype.Map{"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}}},
ip: "1.1.0.0",
expectedNetwork: "1.1.0.0/24",
expectedGetValue: mmdbtype.Map{
"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}},
},
expectedLookupValue: func() *any {
v := any(map[string]any{"a": []any{uint64(1), []byte{1, 2}}})
return &v
Expand All @@ -480,7 +492,9 @@ func TestTreeInsertAndGet(t *testing.T) {
network: "1.1.0.0/24",
start: "1.1.0.0",
end: "1.1.0.255",
value: mmdbtype.Map{"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}}},
value: mmdbtype.Map{
"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}},
},
},
{
network: "1.1.0.128/26",
Expand All @@ -496,14 +510,18 @@ func TestTreeInsertAndGet(t *testing.T) {
end: "1.1.0.191",
// We intentionally don't use the same variable for
// here and above as we want them to be different instances.
value: mmdbtype.Map{"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}}},
value: mmdbtype.Map{
"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}},
},
},
},
gets: []testGet{
{
ip: "1.1.0.0",
expectedNetwork: "1.1.0.0/24",
expectedGetValue: mmdbtype.Map{"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}}},
ip: "1.1.0.0",
expectedNetwork: "1.1.0.0/24",
expectedGetValue: mmdbtype.Map{
"a": mmdbtype.Slice{mmdbtype.Uint64(1), mmdbtype.Bytes{1, 2}},
},
expectedLookupValue: func() *any {
v := any(map[string]any{"a": []any{uint64(1), []byte{1, 2}}})
return &v
Expand Down Expand Up @@ -653,7 +671,13 @@ func TestTreeInsertAndGet(t *testing.T) {
//nolint:forbidigo // code predates netip
network, value := tree.Get(net.ParseIP(get.ip))

assert.Equal(t, get.expectedNetwork, network.String(), "network for %s", get.ip)
assert.Equal(
t,
get.expectedNetwork,
network.String(),
"network for %s",
get.ip,
)
assert.Equal(t, get.expectedGetValue, value, "value for %s", get.ip)
}

Expand Down Expand Up @@ -692,7 +716,12 @@ func TestTreeInsertAndGet(t *testing.T) {

checkMMDB(t, loadBuf, test.gets, "MMDB lookups on Load tree")

assert.Equal(t, bufBytes, loadBuf.Bytes(), "Load + WriteTo generates an identical database")
assert.Equal(
t,
bufBytes,
loadBuf.Bytes(),
"Load + WriteTo generates an identical database",
)
})
}
})
Expand All @@ -712,7 +741,13 @@ func checkMMDB(t *testing.T, buf *bytes.Buffer, gets []testGet, name string) {
network, ok, err := reader.LookupNetwork(net.ParseIP(get.ip), &v)
require.NoError(t, err)

assert.Equal(t, get.expectedNetwork, network.String(), "network for %s in database", get.ip)
assert.Equal(
t,
get.expectedNetwork,
network.String(),
"network for %s in database",
get.ip,
)

if get.expectedLookupValue == nil {
assert.False(t, ok, "%s is not in the database", get.ip)
Expand Down

0 comments on commit 9b7645c

Please sign in to comment.