From 5efd1e717f46badf991aeedaf88df3cc3645c26f Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Tue, 21 Apr 2015 06:50:36 -0700 Subject: [PATCH] Add FakeEC2 Instances support for matching by instance id --- pkg/cloudprovider/aws/aws_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/cloudprovider/aws/aws_test.go b/pkg/cloudprovider/aws/aws_test.go index 79c89ea5cf0..382f1dab85d 100644 --- a/pkg/cloudprovider/aws/aws_test.go +++ b/pkg/cloudprovider/aws/aws_test.go @@ -164,12 +164,25 @@ type FakeEC2 struct { instances []ec2.Instance } +func contains(haystack []string, needle string) bool { + for _, s := range haystack { + if needle == s { + return true + } + } + return false +} + func (self *FakeEC2) Instances(instanceIds []string, filter *ec2InstanceFilter) (resp *ec2.InstancesResp, err error) { matches := []ec2.Instance{} for _, instance := range self.instances { - if filter == nil || filter.Matches(instance) { - matches = append(matches, instance) + if filter != nil && !filter.Matches(instance) { + continue } + if instanceIds != nil && !contains(instanceIds, instance.InstanceId) { + continue + } + matches = append(matches, instance) } return &ec2.InstancesResp{"", []ec2.Reservation{