forked from rnixik/durak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents_test.go
38 lines (33 loc) · 944 Bytes
/
events_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 main
import "testing"
type TestEvent struct {
Field1 string `json:"field1"`
Field2 int `json:"field2"`
}
func TestEventToJSON(t *testing.T) {
event := &TestEvent{"test", 123}
got, err := eventToJSON(event)
if err != nil {
t.Fatalf("TestEventToJSON got error: %s", err)
}
expected := "{\"name\":\"TestEvent\",\"data\":{\"field1\":\"test\",\"field2\":123}}"
if string(got) != expected {
t.Errorf("TestEventToJSON expected: %s, got: %s", expected, got)
}
}
func TestGetNameOfStructPointer(t *testing.T) {
event := &TestEvent{}
got := getNameOfStruct(event)
expected := "TestEvent"
if got != expected {
t.Errorf("TestGetNameOfStructPointer expected: %s, got: %s", expected, got)
}
}
func TestGetNameOfStructValue(t *testing.T) {
event := TestEvent{}
got := getNameOfStruct(event)
expected := "TestEvent"
if got != expected {
t.Errorf("TestGetNameOfStructPointer expected: %s, got: %s", expected, got)
}
}