-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitor_test.go
78 lines (67 loc) · 1.38 KB
/
monitor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ec2spotmonitor
import (
"fmt"
"github.com/paddie/goamz/aws"
"github.com/paddie/goamz/ec2"
// "runtime"
"testing"
"time"
)
func TestMonitorInvalidDesc(t *testing.T) {
auth, err := aws.EnvAuth()
if err != nil {
panic(err)
}
s := ec2.New(auth, aws.EUWest)
d, err := NewEC2InstanceDesc(s, "adfg", "asdf", "asd")
if err != nil {
t.Fatal(err)
}
m, err := d.StartChangeMonitor(time.Second * 1)
if err != nil {
t.Fatal(err)
}
quit := make(chan bool)
go func() {
for trace := range m.TraceChan {
if trace.err == nil {
t.Error("Monitor didn't fail on invalid arguments")
}
// only run once
fmt.Println(trace.err.Error())
quit <- true
}
}()
// wait for the error to return after a tick
<-quit
// exit the monitor
m.Quit()
}
func TestMonitor(t *testing.T) {
t.SkipNow()
m, err := desc.StartUpdateMonitor(time.Second * 1)
// m, err := NewMonitor(auth, aws.EUWest, filter, time.Second*2)
if err != nil {
t.Fatal(err)
}
// run for 10 seconds
quit := time.After(time.Second * 10)
// tick := time.NewTicker(time.Second)
go func() {
for trace := range m.TraceChan {
if trace.err != nil {
t.Fatal(trace.err)
}
if len(trace.Items) == 0 {
fmt.Println("No results..")
continue
}
for _, item := range trace.Items {
fmt.Printf("Price change: %#v\n", *item)
}
}
fmt.Println("exiting test")
}()
<-quit
m.Quit()
}