Skip to content

Commit 63caa79

Browse files
committed
Improve testing helper
1 parent 444c7c2 commit 63caa79

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

api.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

ui.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ func newHelpTable() *termui.Par {
255255

256256
func (ui *UI) triggerInstancesUpdate() {
257257
go ui.api.List("")
258+
// go ui.api.ExampleList()
258259
}
259260

260261
func (ui *UI) refreshInstancesTable() {

0 commit comments

Comments
 (0)