1package agent 2 3import ( 4 "sync" 5 6 "github.com/hashicorp/serf/serf" 7) 8 9// MockEventHandler is an EventHandler implementation that can be used 10// for tests. 11type MockEventHandler struct { 12 Events []serf.Event 13 sync.Mutex 14} 15 16func (h *MockEventHandler) HandleEvent(e serf.Event) { 17 h.Lock() 18 defer h.Unlock() 19 h.Events = append(h.Events, e) 20} 21 22// MockQueryHandler is an EventHandler implementation used for tests, 23// it always responds to a query with a given response 24type MockQueryHandler struct { 25 Response []byte 26 Queries []*serf.Query 27 sync.Mutex 28} 29 30func (h *MockQueryHandler) HandleEvent(e serf.Event) { 31 query, ok := e.(*serf.Query) 32 if !ok { 33 return 34 } 35 36 h.Lock() 37 h.Queries = append(h.Queries, query) 38 h.Unlock() 39 40 query.Respond(h.Response) 41} 42