-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathevent_test.go
38 lines (35 loc) · 937 Bytes
/
event_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
package pusher
import (
"encoding/json"
"fmt"
"strings"
"testing"
)
func TestEventErrorError(t *testing.T) {
err := EventError{
Message: "foo",
Code: 123,
}
errMsg := err.Error()
if !strings.Contains(errMsg, "code 123") {
t.Errorf("Expected error message to contain 'code 123', got %s", errMsg)
}
if !strings.Contains(errMsg, `message "foo"`) {
t.Errorf(`Expected error message to contain 'message "foo"', got %s`, errMsg)
}
}
func TestExtractEventError(t *testing.T) {
wantMessage := "foo"
wantCode := 123
event := Event{
Data: json.RawMessage(fmt.Sprintf(`{"message":"%s","code":%d}`, wantMessage, wantCode)),
}
err := extractEventError(event)
evtErr := err.(EventError)
if evtErr.Message != wantMessage {
t.Errorf("Expected error message to be %s, got %s", wantMessage, evtErr.Message)
}
if evtErr.Code != wantCode {
t.Errorf("Expected error code to be %d, got %d", wantCode, evtErr.Code)
}
}