2015-01-06 18:40:00 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-05-12 19:10:25 +00:00
|
|
|
|
2017-04-29 16:34:02 +00:00
|
|
|
"github.com/hashicorp/consul/testutil/retry"
|
2015-01-06 18:40:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEvent_FireList(t *testing.T) {
|
2015-05-08 17:27:24 +00:00
|
|
|
t.Parallel()
|
2015-01-06 23:26:50 +00:00
|
|
|
c, s := makeClient(t)
|
2015-03-03 02:18:38 +00:00
|
|
|
defer s.Stop()
|
2015-01-06 23:26:50 +00:00
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
event := c.Event()
|
|
|
|
|
|
|
|
params := &UserEvent{Name: "foo"}
|
|
|
|
id, meta, err := event.Fire(params, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if meta.RequestTime == 0 {
|
|
|
|
t.Fatalf("bad: %v", meta)
|
|
|
|
}
|
|
|
|
|
|
|
|
if id == "" {
|
|
|
|
t.Fatalf("invalid: %v", id)
|
|
|
|
}
|
|
|
|
|
2015-05-12 19:10:25 +00:00
|
|
|
var events []*UserEvent
|
|
|
|
var qm *QueryMeta
|
2017-04-29 16:34:02 +00:00
|
|
|
|
|
|
|
retry.Run("", t, func(r *retry.R) {
|
2015-05-12 19:10:25 +00:00
|
|
|
events, qm, err = event.List("", nil)
|
|
|
|
if err != nil {
|
2017-04-29 16:34:02 +00:00
|
|
|
r.Fatalf("err: %v", err)
|
2015-05-12 19:10:25 +00:00
|
|
|
}
|
2017-04-29 16:34:02 +00:00
|
|
|
if len(events) <= 0 {
|
|
|
|
r.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
2015-05-12 19:10:25 +00:00
|
|
|
|
|
|
|
if events[len(events)-1].ID != id {
|
|
|
|
t.Fatalf("bad: %#v", events)
|
2015-01-06 18:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if qm.LastIndex != event.IDToIndex(id) {
|
|
|
|
t.Fatalf("Bad: %#v", qm)
|
|
|
|
}
|
|
|
|
}
|