Documentation ¶
Overview ¶
Package xmpptest provides utilities for XMPP testing.
Index ¶
- func NewClientSession(finalState xmpp.SessionState, rw io.ReadWriter) *xmpp.Session
- func NewServerSession(finalState xmpp.SessionState, rw io.ReadWriter) *xmpp.Session
- func NopNegotiator(state xmpp.SessionState, streamNS string) xmpp.Negotiator
- func RunEncodingTests(t *testing.T, testCases []EncodingTestCase)
- func RunFeatureTests(t *testing.T, tcs []FeatureTestCase)
- func RunTransformerTests(t *testing.T, T xmlstream.Transformer, tcs []TransformerTestCase)
- type ClientServer
- type EncodingTestCase
- type FeatureTestCase
- type Option
- func ClientHandler(handler xmpp.Handler) Option
- func ClientHandlerFunc(handler xmpp.HandlerFunc) Option
- func ClientState(state xmpp.SessionState) Option
- func ServerHandler(handler xmpp.Handler) Option
- func ServerHandlerFunc(handler xmpp.HandlerFunc) Option
- func ServerState(state xmpp.SessionState) Option
- type Tokens
- type TransformerTestCase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClientSession ¶ added in v0.20.0
func NewClientSession(finalState xmpp.SessionState, rw io.ReadWriter) *xmpp.Session
NewClientSession returns a new client-to-client XMPP session with the state bits set to finalState|xmpp.Ready, the origin JID set to "test@example.net" and the location JID set to "example.net".
NewClientSession panics on error for ease of use in testing, where a panic is acceptable.
func NewServerSession ¶ added in v0.20.0
func NewServerSession(finalState xmpp.SessionState, rw io.ReadWriter) *xmpp.Session
NewServerSession is like NewClientSession except that the stream uses the server-to-server namespace.
func NopNegotiator ¶ added in v0.7.1
func NopNegotiator(state xmpp.SessionState, streamNS string) xmpp.Negotiator
NopNegotiator marks the state as ready (by returning state|xmpp.Ready) and pops the first token (likely <stream:stream>) but does not perform any validation on the token, transmit any data over the wire, or perform any other session negotiation.
func RunEncodingTests ¶ added in v0.19.0
func RunEncodingTests(t *testing.T, testCases []EncodingTestCase)
RunEncodingTests iterates over the test cases and runs each one.
func RunFeatureTests ¶ added in v0.18.0
func RunFeatureTests(t *testing.T, tcs []FeatureTestCase)
RunFeatureTests simulates a stream feature neogtiation and tests the output.
func RunTransformerTests ¶ added in v0.22.0
func RunTransformerTests(t *testing.T, T xmlstream.Transformer, tcs []TransformerTestCase)
Types ¶
type ClientServer ¶ added in v0.17.1
type ClientServer struct { Client *xmpp.Session Server *xmpp.Session // contains filtered or unexported fields }
ClientServer is two coupled xmpp.Session's that can respond to one another in tests.
func NewClientServer ¶ added in v0.17.1
func NewClientServer(opts ...Option) *ClientServer
NewClientServer returns a ClientServer with the client and server goroutines started. Both serve goroutines are started when NewClientServer is called and shut down when the ClientServer is closed.
func (*ClientServer) Close ¶ added in v0.17.1
func (cs *ClientServer) Close() error
Close calls the client and server sessions' close methods.
type EncodingTestCase ¶ added in v0.19.0
type EncodingTestCase struct { Value interface{} XML string Err error NoMarshal bool NoUnmarshal bool }
EncodingTestCase is a test that marshals the value and checks that the result matches XML, then unmarshals XML into a new zero value of the type in value and checks that it matches the original value with reflect.DeepEqual. If NoMarshal or NoUnmarshal is set then the corresponding part of the test is not run (for payloads that are not roundtrippable).
type FeatureTestCase ¶ added in v0.18.0
type FeatureTestCase struct { State xmpp.SessionState Feature xmpp.StreamFeature In string Out string FinalState xmpp.SessionState Err error }
FeatureTestCase is a data driven test for stream feature negotiation.
type Option ¶ added in v0.17.1
type Option func(*ClientServer)
Option is a type for configuring a ClientServer.
func ClientHandler ¶ added in v0.17.1
ClientHandler sets up the client side of a ClientServer.
func ClientHandlerFunc ¶ added in v0.17.1
func ClientHandlerFunc(handler xmpp.HandlerFunc) Option
ClientHandlerFunc sets up the client side of a ClientServer using an xmpp.HandlerFunc.
func ClientState ¶ added in v0.17.1
func ClientState(state xmpp.SessionState) Option
ClientState configures extra state bits to add to the client session.
func ServerHandler ¶ added in v0.17.1
ServerHandler sets up the server side of a ClientServer.
func ServerHandlerFunc ¶ added in v0.17.1
func ServerHandlerFunc(handler xmpp.HandlerFunc) Option
ServerHandlerFunc sets up the server side of a ClientServer using an xmpp.HandlerFunc.
func ServerState ¶ added in v0.17.1
func ServerState(state xmpp.SessionState) Option
ServerState configures extra state bits to add to the server session.
type Tokens ¶ added in v0.18.0
Tokens is a slice of XML tokens that can also act as an xml.TokenReader by popping tokens from itself. This is useful for testing contrived scenarios where the tokens cannot be constructed using an xml.Decoder because the stream to be tested violates the well-formedness rules of XML or otherwise would result in an error from the decoder.
type TransformerTestCase ¶ added in v0.22.0
type TransformerTestCase struct { In string Out string // If InStream is not nil, it will be used instead of "In" and should result // in tokens matching Out. InStream xml.TokenReader }
TransformerTestCase is a data driven test for XML transformers.