func TestClient_FeaturesTracking(t *testing.T) {
	mock := ServerMock{}
	mock.Start(t, testXMPPAddress, func(t *testing.T, sc *ServerConn) {
		handlerAbortTLS(t, sc)
		closeConn(t, sc)
	})
	config := Config{
		TransportConfiguration: TransportConfiguration{
			Address: testXMPPAddress,
		},
		Jid:        "test@localhost",
		Credential: Password("test"),
	}
	var client *Client
	var err error
	router := NewRouter()
	if client, err = NewClient(&config, router, clientDefaultErrorHandler); err != nil {
		t.Errorf("cannot create XMPP client: %s", err)
	}
	if err = client.Connect(); err == nil {
		t.Errorf("should fail as insecure connection is not allowed and server does not support TLS")
	}
	mock.Stop()
}
Check that the client is properly tracking features, as session negotiation progresses.
package xmpp
import (
	"context"
	"encoding/xml"
	"errors"
	"fmt"
	"testing"
	"time"
	"gosrc.io/xmpp/stanza"
)
const (
	testXMPPAddress  = "localhost:15222"
	testClientDomain = "localhost"
)
func TestEventManager(t *testing.T) {
	mgr := EventManager{}
	mgr.updateState(StateResuming)
	if mgr.CurrentState.getState() != StateResuming {
		t.Fatal("CurrentState not updated by updateState()")
	}
	mgr.disconnected(SMState{})
	if mgr.CurrentState.getState() != StateDisconnected {
		t.Fatalf("CurrentState not reset by disconnected()")
	}
	mgr.streamError(ErrTLSNotSupported.Error(), "")
	if mgr.CurrentState.getState() != StateStreamError {
		t.Fatalf("CurrentState not set by streamError()")
	}
}
func TestClient_Connect(t *testing.T) {
	mock := ServerMock{}
	mock.Start(t, testXMPPAddress, handlerClientConnectSuccess)
	config := Config{
		TransportConfiguration: TransportConfiguration{
			Address: testXMPPAddress,
		},
		Jid:        "test@localhost",
		Credential: Password("test"),
		Insecure:   true}
	var client *Client
	var err error
	router := NewRouter()
	if client, err = NewClient(&config, router, clientDefaultErrorHandler); err != nil {
		t.Errorf("connect create XMPP client: %s", err)
	}
	if err = client.Connect(); err != nil {
		t.Errorf("XMPP connection failed: %s", err)
	}
	mock.Stop()
}
func TestClient_NoInsecure(t *testing.T) {
	mock := ServerMock{}
	mock.Start(t, testXMPPAddress, func(t *testing.T, sc *ServerConn) {
		handlerAbortTLS(t, sc)
		closeConn(t, sc)
	})
	config := Config{
		TransportConfiguration: TransportConfiguration{
			Address: testXMPPAddress,
		},
		Jid:        "test@localhost",
		Credential: Password("test"),
	}
	var client *Client
	var err error
	router := NewRouter()
	if client, err = NewClient(&config, router, clientDefaultErrorHandler); err != nil {
		t.Errorf("cannot create XMPP client: %s", err)
	}
	if err = client.Connect(); err == nil {
		t.Errorf("should fail as insecure connection is not allowed and server does not support TLS")
	}
	mock.Stop()
}