forked from pragmaticivan/gosocketio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener_test.go
44 lines (34 loc) · 945 Bytes
/
listener_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
42
43
44
package socketio
import (
"reflect"
"testing"
)
func TestHandlerNotFunction(t *testing.T) {
var notFunction []string
var h, err = NewHandler(notFunction)
if h != nil {
t.Errorf("Expected no listener to be returned")
}
if err == nil || err.Error() != "listener is a slice instead of a function" {
t.Errorf("Expected error doesn't match expected value, got %v", err)
}
switch err.(type) {
case ErrorNotFunction:
default:
t.Errorf("Expected error to be of type NotFunctionError")
}
}
func TestHandlerValidFunction(t *testing.T) {
var _, err = NewHandler(mockHandlerStringInAndNumberOut)
if err != nil {
t.Errorf("Expected no error, got %v instead", err)
}
}
func TestParamKindInvalid(t *testing.T) {
if err := checkParamKind(reflect.Func); err == nil {
t.Errorf("Expected error when passing invalid parameter kind, got %v instead", err)
}
}
func mockHandlerStringInAndNumberOut(s string) int {
return len(s)
}