@@ -85,18 +85,37 @@ func (api *API) List(nameFilter string) ([]*ec2.Instance, error) {
8585}
8686
8787// ExampleList returns a fake list of instances (used for testing)
88- func ExampleList () []* ec2.Instance {
89- count := 5
90- list := []* ec2.Instance {}
88+ func ( api * API ) ExampleList () ( []* ec2.Instance , error ) {
89+ count := 10
90+ instances := []* ec2.Instance {}
9191 for i := 0 ; i < count ; i ++ {
9292 id := fmt .Sprintf ("i-%d" , i )
93- hostname := fmt .Sprintf ("ec2-52-59-245-%d.eu-central-1.compute.amazonaws.com" , i )
93+ publicDNS := fmt .Sprintf ("ec2-52-59-245-%d.eu-central-1.compute.amazonaws.com" , i )
94+ privateDNS := fmt .Sprintf ("ip-10-0-0-%d.eu-central-1.compute.internal" , i )
95+ tagPurpose := ec2.Tag {}
96+ tagPurpose .SetKey ("Purpose" )
97+ tagPurpose .SetValue ("webapp" )
98+ instanceType := "t2.medium"
99+ availabilityZone := "eu-central-1"
100+ now := time .Now ()
101+ state := "running"
102+
94103 instance := & ec2.Instance {
95- InstanceId : & id ,
96- PublicDnsName : & hostname ,
104+ InstanceId : & id ,
105+ PublicDnsName : & publicDNS ,
106+ PrivateDnsName : & privateDNS ,
107+ Tags : []* ec2.Tag {& tagPurpose },
108+ InstanceType : & instanceType ,
109+ Placement : & ec2.Placement {AvailabilityZone : & availabilityZone },
110+ LaunchTime : & now ,
111+ State : & ec2.InstanceState {Name : & state },
97112 }
98- list = append (list , instance )
113+ instances = append (instances , instance )
99114 }
100115
101- return list
116+ api .cache .instances = instances
117+ api .cache .time = time .Now ()
118+ api .instancesChan <- instances
119+
120+ return instances , nil
102121}
0 commit comments