forked from rnixik/durak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_test.go
58 lines (43 loc) · 1.14 KB
/
player_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"testing"
)
type MockedClient struct {
mock.Mock
Client
nickname string
}
func (m *MockedClient) sendEvent(event interface{}) {
m.Called(event)
}
func (m *MockedClient) sendMessage(message []byte) {
m.Called(message)
}
type TestPlayerEvent struct {
}
func TestSendEvent(t *testing.T) {
mockedClient := &MockedClient{}
player := newPlayer(mockedClient, false)
event := &TestPlayerEvent{}
mockedClient.On("sendEvent", event).Return()
player.sendEvent(event)
mockedClient.AssertCalled(t, "sendEvent", event)
}
func TestSendMessage(t *testing.T) {
mockedClient := &MockedClient{}
player := newPlayer(mockedClient, false)
message := []byte("test")
mockedClient.On("sendMessage", message).Return()
player.sendMessage(message)
mockedClient.AssertCalled(t, "sendMessage", message)
}
func TestNewPlayer(t *testing.T) {
client := &Client{nickname: "test_nickname"}
player := newPlayer(client, true)
assert := assert.New(t)
assert.Equal("test_nickname", player.Name)
assert.Equal(true, player.IsActive)
assert.Equal(client, player.client)
}