Add FakeEC2 Instances support for matching by instance id

This commit is contained in:
Justin Santa Barbara 2015-04-21 06:50:36 -07:00
parent a3e8e80572
commit 5efd1e717f

View File

@ -164,12 +164,25 @@ type FakeEC2 struct {
instances []ec2.Instance 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) { func (self *FakeEC2) Instances(instanceIds []string, filter *ec2InstanceFilter) (resp *ec2.InstancesResp, err error) {
matches := []ec2.Instance{} matches := []ec2.Instance{}
for _, instance := range self.instances { for _, instance := range self.instances {
if filter == nil || filter.Matches(instance) { if filter != nil && !filter.Matches(instance) {
matches = append(matches, instance) continue
} }
if instanceIds != nil && !contains(instanceIds, instance.InstanceId) {
continue
}
matches = append(matches, instance)
} }
return &ec2.InstancesResp{"", return &ec2.InstancesResp{"",
[]ec2.Reservation{ []ec2.Reservation{