-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
handler_test.go
41 lines (33 loc) · 1.25 KB
/
handler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2020 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.
package xmpp_test
import (
"encoding/xml"
"errors"
"testing"
"mellium.im/xmlstream"
"mellium.im/xmpp"
)
var errHandlerFuncSentinal = errors.New("handler test")
type sentinalReadWriter struct{}
func (sentinalReadWriter) Token() (xml.Token, error) { return nil, nil }
func (sentinalReadWriter) EncodeToken(xml.Token) error { return nil }
func (sentinalReadWriter) Encode(interface{}) error { return nil }
func (sentinalReadWriter) EncodeElement(interface{}, xml.StartElement) error { return nil }
func TestHandlerFunc(t *testing.T) {
s := &xml.StartElement{}
var f xmpp.HandlerFunc = func(r xmlstream.TokenReadEncoder, start *xml.StartElement) error {
if _, ok := r.(sentinalReadWriter); !ok {
t.Errorf("HandleXMPP did not pass reader to HandlerFunc")
}
if start != s {
t.Errorf("HandleXMPP did not pass start token to HandlerFunc")
}
return errHandlerFuncSentinal
}
err := f.HandleXMPP(sentinalReadWriter{}, s)
if err != errHandlerFuncSentinal {
t.Errorf("HandleXMPP did not return handlerfunc error, got %q", err)
}
}