mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-26 20:32:02 -08:00
Merge pull request #136 from Crypho/eventmanager-status
Fix updating of EventManager.CurrentState
This commit is contained in:
commit
b74c0f0374
@ -60,21 +60,21 @@ type EventManager struct {
|
|||||||
Handler EventHandler
|
Handler EventHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em EventManager) updateState(state ConnState) {
|
func (em *EventManager) updateState(state ConnState) {
|
||||||
em.CurrentState = state
|
em.CurrentState = state
|
||||||
if em.Handler != nil {
|
if em.Handler != nil {
|
||||||
em.Handler(Event{State: em.CurrentState})
|
em.Handler(Event{State: em.CurrentState})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em EventManager) disconnected(state SMState) {
|
func (em *EventManager) disconnected(state SMState) {
|
||||||
em.CurrentState = StateDisconnected
|
em.CurrentState = StateDisconnected
|
||||||
if em.Handler != nil {
|
if em.Handler != nil {
|
||||||
em.Handler(Event{State: em.CurrentState, SMState: state})
|
em.Handler(Event{State: em.CurrentState, SMState: state})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em EventManager) streamError(error, desc string) {
|
func (em *EventManager) streamError(error, desc string) {
|
||||||
em.CurrentState = StateStreamError
|
em.CurrentState = StateStreamError
|
||||||
if em.Handler != nil {
|
if em.Handler != nil {
|
||||||
em.Handler(Event{State: em.CurrentState, StreamError: error, Description: desc})
|
em.Handler(Event{State: em.CurrentState, StreamError: error, Description: desc})
|
||||||
|
@ -19,6 +19,24 @@ const (
|
|||||||
defaultTimeout = 2 * time.Second
|
defaultTimeout = 2 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestEventManager(t *testing.T) {
|
||||||
|
mgr := EventManager{}
|
||||||
|
mgr.updateState(StateConnected)
|
||||||
|
if mgr.CurrentState != StateConnected {
|
||||||
|
t.Fatal("CurrentState not updated by updateState()")
|
||||||
|
}
|
||||||
|
|
||||||
|
mgr.disconnected(SMState{})
|
||||||
|
if mgr.CurrentState != StateDisconnected {
|
||||||
|
t.Fatalf("CurrentState not reset by disconnected()")
|
||||||
|
}
|
||||||
|
|
||||||
|
mgr.streamError(ErrTLSNotSupported.Error(), "")
|
||||||
|
if mgr.CurrentState != StateStreamError {
|
||||||
|
t.Fatalf("CurrentState not set by streamError()")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestClient_Connect(t *testing.T) {
|
func TestClient_Connect(t *testing.T) {
|
||||||
// Setup Mock server
|
// Setup Mock server
|
||||||
mock := ServerMock{}
|
mock := ServerMock{}
|
||||||
|
Loading…
Reference in New Issue
Block a user