Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NetworksWithin #65

Merged
merged 8 commits into from
Jan 15, 2020
Merged

Add NetworksWithin #65

merged 8 commits into from
Jan 15, 2020

Conversation

oalders
Copy link
Contributor

@oalders oalders commented Jan 9, 2020

No description provided.

@oalders oalders marked this pull request as ready for review January 10, 2020 16:10
Copy link
Owner

@oschwald oschwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I had a few small comments.

traverse_test.go Outdated
@@ -46,3 +47,262 @@ func TestNetworksWithInvalidSearchTree(t *testing.T) {
assert.NotNil(t, n.Err(), "no error received when traversing an broken search tree")
assert.Equal(t, n.Err().Error(), "invalid search tree at 128.128.128.128/32")
}

func TestNetworksWithinV4SearchInV4Db(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These probably could have been a single table driven test given that the structure of each test is pretty much identical.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've cleaned these up. The tests are now much more succinct.

"1.1.1.1/32",
"1.1.1.2/31",
"1.1.1.4/30",
"1.1.1.8/29",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have a test that selects multiple records, but only a subset of the ones within an address space. For instance, 81.2.69.128/26 in the GeoIP2 Country test database.

traverse_test.go Outdated
}

func TestNetworksWithinV6SearchInV6Db(t *testing.T) {
var network = &net.IPNet{IP: make(net.IP, 16), Mask: net.CIDRMask(0, 128)}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next three test functions largely duplicate the Networks() test. I think we would get better coverage of the expected behaviors by searching within limited subnets for them.

return networks
}

func (r *Reader) NetworksWithin(network *net.IPNet) *Networks {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs documentation. I think your earlier PR had documentation. Also, an example similar to this one for Networks() would be nice:

func ExampleReader_Networks() {

This would get included in the generated documentation.

@oalders oalders changed the title Allow ipv4 searches in an ipv6 db Add NetworksWithin Jan 13, 2020
@oalders oalders requested a review from oschwald January 14, 2020 14:29
@oalders
Copy link
Contributor Author

oalders commented Jan 15, 2020

I think I have addressed all of the comments. I'm happy to make more changes if needed.

}

// NetworksWithin returns an iterator that can be used to traverse all networks
// in the database which are contained in a given network.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note clarifying what happens when the provided network is within a network in the database would be worthwhile, e.g., something like, "If the provided network is contained within a network in the database, the iterator will iterate over exactly one network, the containing network." I am not attached to the wording so feel free to make it clearer.

Copy link
Contributor Author

@oalders oalders Jan 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! Added in 5e7ecc7

Expected []string
}

var tests = []networkTest{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I notice that we don't have any tests for networks with no records. Could you add a test case for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 5800f39

in the case where the network being searched is contained within another
network.
@oschwald oschwald merged commit 664f3fe into oschwald:master Jan 15, 2020
@oalders oalders deleted the greg/networks-within-poc branch January 15, 2020 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants