-
Notifications
You must be signed in to change notification settings - Fork 104
/
entity_test.go
164 lines (148 loc) · 3.99 KB
/
entity_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package manta
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEntityOpFlag(t *testing.T) {
assert := assert.New(t)
assert.True(EntityOpCreated.Flag(EntityOpCreated))
assert.False(EntityOpCreated.Flag(EntityOpDeleted))
assert.False(EntityOpCreated.Flag(EntityOpEntered))
assert.True(EntityOpCreatedEntered.Flag(EntityOpCreated))
assert.True(EntityOpCreatedEntered.Flag(EntityOpEntered))
assert.False(EntityOpCreatedEntered.Flag(EntityOpDeleted))
assert.False(EntityOpCreatedEntered.Flag(EntityOpLeft))
}
type expectedEntity struct {
class string
property string
value interface{}
}
type entityTestScenario struct {
matchId string
replayUrl string
tick uint32
entities []expectedEntity
skipInCI bool
}
var entityTestScenarios = map[int64]entityTestScenario{
3534483793: {
matchId: "3534483793",
replayUrl: "https://s3-us-west-2.amazonaws.com/manta.dotabuff/3534483793.dem",
tick: 22000,
entities: []expectedEntity{
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerTeamData.0001.m_nSelectedHeroID",
value: int32(21),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerTeamData.0001.m_iKills",
value: int32(4),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerTeamData.0001.m_hSelectedHero",
value: uint64(11961313),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerData.0001.m_bIsValid",
value: true,
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerData.0001.m_iPlayerTeam",
value: int32(2),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerData.0001.m_iPlayerSteamID",
value: uint64(76561198140280423),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerData.0002.m_iszPlayerName",
value: "ARMYANO",
},
},
},
3619005274: {
matchId: "3619005274",
replayUrl: "https://s3-us-west-2.amazonaws.com/manta.dotabuff/3619005274.dem",
tick: 2,
entities: []expectedEntity{
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerTeamData.0000.m_nSelectedHeroID",
value: int32(94),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerTeamData.0000.m_iKills",
value: int32(0),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerTeamData.0000.m_hSelectedHero",
value: uint64(8750018),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerData.0000.m_bIsValid",
value: true,
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerData.0000.m_iPlayerTeam",
value: int32(2),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerData.0000.m_iPlayerSteamID",
value: uint64(76561198134146057),
},
{
class: "CDOTA_PlayerResource",
property: "m_vecPlayerData.0002.m_iszPlayerName",
value: "@dogf1ghts", // are very wrong
},
},
},
}
func TestEntities3534483793(t *testing.T) { entityTestScenarios[3534483793].test(t) }
func TestEntities3619005274(t *testing.T) { entityTestScenarios[3619005274].test(t) }
func (s entityTestScenario) test(t *testing.T) {
assert := assert.New(t)
if s.skipInCI && os.Getenv("CI") != "" {
t.Skip("skipping scenario in CI environment")
}
r := mustGetReplayReader(s.matchId, s.replayUrl)
defer r.Close()
parser, err := NewStreamParser(r)
if !assert.Nil(err, "unable to instantiate parser: %s", err) {
return
}
parser.parseToTick(s.tick)
err = parser.Start()
if !assert.Nil(err, s.matchId) {
return
}
for _, ee := range s.entities {
found := false
for _, ae := range parser.entities {
if ae == nil || ae.class == nil {
continue
}
if ae.class.name == ee.class {
found = true
assert.Equal(ee.value, ae.Get(ee.property),
"unexpected value for class %s property %s at tick %d", ee.class, ee.property, s.tick)
break
}
}
assert.True(found, "unable to find entity %s at tick %d", ee.class, s.tick)
}
}