github.phpd.cn/hashicorp/consul@v1.4.5/api/event_test.go (about) 1 package api 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/consul/testutil/retry" 7 ) 8 9 func TestAPI_EventFireList(t *testing.T) { 10 t.Parallel() 11 c, s := makeClient(t) 12 defer s.Stop() 13 14 event := c.Event() 15 16 params := &UserEvent{Name: "foo"} 17 id, meta, err := event.Fire(params, nil) 18 if err != nil { 19 t.Fatalf("err: %v", err) 20 } 21 22 if meta.RequestTime == 0 { 23 t.Fatalf("bad: %v", meta) 24 } 25 26 if id == "" { 27 t.Fatalf("invalid: %v", id) 28 } 29 30 var events []*UserEvent 31 var qm *QueryMeta 32 33 retry.Run(t, func(r *retry.R) { 34 events, qm, err = event.List("", nil) 35 if err != nil { 36 r.Fatalf("err: %v", err) 37 } 38 if len(events) <= 0 { 39 r.Fatal(err) 40 } 41 }) 42 43 if events[len(events)-1].ID != id { 44 t.Fatalf("bad: %#v", events) 45 } 46 47 if qm.LastIndex != event.IDToIndex(id) { 48 t.Fatalf("Bad: %#v", qm) 49 } 50 }