Improved NetworkInterfaces() filtering support for ec2test #20

Merged
merged 2 commits into from Jan 20, 2015

Conversation

Projects
None yet
2 participants
Member

dimitern commented Jan 19, 2015

Added most of the filters supported by DescribeNetworkInterfaces() to the ec2test server. None of the Elastic IP related filters or tags are supported by ec2test, but we can now write tests for NICs that filter by instance-id for example. Some changes to ec2test were needed to mimic EC2 behavior better.

The existing TestNetworkInterfaces test was refactored and reused for the new TestNetworkInterfacesFiltering test. Both tests share most of the setup code.

ec2/ec2test/server.go
fatalf(400, "InvalidParameterValue", "describe ifaces: %v", err)
}
+ _, requestedByID := idMap[i.Id]
+ if len(idMap) == 0 {
+ // since filter.ok() returns true when none matches, we
@axw

axw Jan 20, 2015

Member

This is confusing.

I think you mean that filter.ok() returns true when there are no filters specified, and so not specifying an ID means you don't implicitly filter by ID either.

I think this would be easier to understand, and would not require commentary, if you checked len(idMap) == 0 || idMap[i.Id] before everything else, continuing if the test fails.

@dimitern

dimitern Jan 20, 2015

Member

Looking at it this morning it does look confusing :)
I've simplified the code to a single conditional: if filterMatch && (len(idMap) == 0 || idMap[i.Id] { ..., which works for all cases. Thanks!

ec2/ec2test/server.go
- ok, err := f.ok(i)
- _, known := idMap[i.Id]
- if ok && (len(idMap) == 0 || known) {
+ // Without neither filers nor ids - return everything.
@axw

axw Jan 20, 2015

Member

s/filers/filters/
s/Without/With/
(or "Without either filters or ids")

@dimitern

dimitern Jan 20, 2015

Member

D'oh! Nice catch, but I've simplified the code as you suggested below and this is now gone.

Member

axw commented Jan 20, 2015

A couple of quibbles, but otherwise LGTM.

dimitern pushed a commit that referenced this pull request Jan 20, 2015

Merge pull request #20 from dimitern/v2-ec2test-describenetworkinterf…
…aces-filtering

Improved NetworkInterfaces() filtering support for ec2test

@dimitern dimitern merged commit 852014c into go-amz:v2 Jan 20, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@dimitern dimitern deleted the dimitern:v2-ec2test-describenetworkinterfaces-filtering branch Jan 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment