-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanifest_test.go
287 lines (255 loc) · 7.21 KB
/
manifest_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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package destiny2
import (
"fmt"
"io/ioutil"
"sort"
"testing"
"github.com/google/go-cmp/cmp"
_ "github.com/mattn/go-sqlite3"
)
func TestUpdate(t *testing.T) {
manifest, err := NewManifest(nil)
if err != nil {
t.Fatal(err)
}
updated := false
onUpdate := func() error {
updated = true
return nil
}
if err := manifest.Update(onUpdate); err != nil {
t.Fatal(err)
}
if updated {
t.Error("Update after NewManifest should not be necessary")
}
manifest = new(Manifest)
if err := manifest.Update(onUpdate); err != nil {
t.Fatal(err)
}
if !updated {
t.Error("Updating empty manifest should be necessary")
}
}
type fulfillmentTests struct {
name string
fn func(t *testing.T)
}
func TestFulfillContract(t *testing.T) {
reader := NewTestReader()
manifest, err := NewManifest(reader)
if err != nil {
t.Fatal(err)
}
defer reader.Close()
tests := []fulfillmentTests{
{
name: "Gender DisplayProperties",
fn: func(t *testing.T) {
var genders GenderDefinition
if err := manifest.FulfillContract(&genders); err != nil {
t.Fatal(err)
}
genderProps := map[Gender]DisplayProperties{
Gender_Male: DisplayProperties{Name: "Masculine"},
Gender_Female: DisplayProperties{Name: "Feminine"},
}
for _, gender := range genders {
prop := genderProps[gender.GenderType]
if diff := cmp.Diff(prop, gender.DisplayProperties); diff != "" {
t.Errorf("Gender DisplayProperties differ: %s", diff)
}
}
},
},
{
name: "Gjallarhorn Lore",
fn: func(t *testing.T) {
const gjallarhornHash = 1363886209
var items InventoryItemDefinition
var lore LoreDefinition
if err := manifest.FulfillContract(&items); err != nil {
t.Fatal(err)
}
if err := manifest.FulfillContract(&lore); err != nil {
t.Fatal(err)
}
horn := items[gjallarhornHash]
hornLore := lore[horn.LoreHash]
if hornLore.Subtitle != horn.FlavorText {
t.Errorf("Gjallarhorn lore is incorrect: want %q, got %q", horn.FlavorText, hornLore.Subtitle)
}
},
},
{
name: "Starhorse Location",
fn: func(t *testing.T) {
const starhorseHash = 3431983428
starhorseLocation := DisplayProperties{
Name: "Eternity",
Description: "A strange pocket dimension where multiple realities from across the paraverse converge and overlap.",
}
var vendors VendorDefinition
var destinations DestinationDefinition
if err := manifest.FulfillContract(&vendors); err != nil {
t.Fatal(err)
}
if err := manifest.FulfillContract(&destinations); err != nil {
t.Fatal(err)
}
starhorse := vendors[starhorseHash]
destination := destinations[starhorse.Locations[0].DestinationHash]
if diff := cmp.Diff(destination.DisplayProperties, starhorseLocation); diff != "" {
t.Errorf("Starhorse's location is incorrect: %s", diff)
}
},
},
{
name: "Find all exotic warlock helments",
fn: func(t *testing.T) {
wantExotics := []string{
"Apotheosis Veil",
"Astrocyte Verse",
"Crown of Tempests",
"Dawn Chorus",
"Eye of Another World",
"Felwinter's Helm",
"Nezarec's Sin",
"Skull of Dire Ahamkara",
"The Stag",
"Verity's Brow",
}
var items InventoryItemDefinition
if err := manifest.FulfillContract(&items); err != nil {
t.Fatal(err)
}
var gotExotics []string
for _, item := range items {
// Skip anything that isn't a warlock-exclusive exotic helmet.
if item.ClassType != Class_Warlock || item.Inventory.TierType != ItemTier_Exotic || item.ItemSubType != SubType_HelmetArmor {
continue
}
// Also, skip exotics that use Armor 1.0 (implementation difference is Armor 2.0 gear has an associated CollectibleHash)
if item.CollectibleHash == 0 {
continue
}
gotExotics = append(gotExotics, item.DisplayProperties.Name)
}
sort.Strings(gotExotics)
if diff := cmp.Diff(wantExotics, gotExotics); diff != "" {
t.Errorf("Did not find all expected warlock exotic helmets: %s", diff)
}
},
},
{
name: "Mobile and component consistency",
fn: func(t *testing.T) {
var lore, mobileLore LoreDefinition
if err := manifest.FulfillContract(&lore); err != nil {
t.Fatal(err)
}
if err := manifest.FulfillContract(&mobileLore, UseMobileManifest(true)); err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(lore, mobileLore); diff != "" {
t.Errorf("Component lore and mobile manifest lore are not consistent: %s", diff)
}
},
},
}
for _, test := range tests {
t.Run(test.name, test.fn)
}
}
// Testing that all contracts can be fulfilled without error.
func TestFulfillContract_All(t *testing.T) {
allContracts := []Contract{
new(ProgressionDefinition),
new(InventoryItemDefinition),
new(InventoryBucketDefinition),
new(ItemTierTypeDefinition),
new(StatDefinition),
new(StatGroupDefinition),
new(EquipmentSlotDefinition),
new(SocketTypeDefinition),
new(SocketCategoryDefinition),
new(DestinationDefinition),
new(ActivityGraphDefinition),
new(ActivityDefinition),
new(ActivityModifierDefinition),
new(ObjectiveDefinition),
new(SandboxPerkDefinition),
new(LocationDefinition),
new(ActivityModeDefinition),
new(PlaceDefinition),
new(ActivityTypeDefinition),
new(VendorGroupDefinition),
new(FactionDefinition),
new(ArtifactDefinition),
new(PowerCapDefinition),
new(ProgressionLevelRequirementDefinition),
new(RewardSourceDefinition),
new(TraitDefinition),
new(TraitCategoryDefinition),
new(PresentationNodeDefinition),
new(CollectibleDefinition),
new(MaterialRequirementSetDefinition),
new(RecordDefinition),
new(GenderDefinition),
new(VendorDefinition),
new(LoreDefinition),
new(MetricDefinition),
new(EnergyTypeDefinition),
new(PlugSetDefinition),
new(TalentGridDefinition),
new(DamageTypeDefinition),
new(ItemCategoryDefinition),
new(BreakerTypeDefinition),
new(SeasonDefinition),
new(SeasonPassDefinition),
new(ChecklistDefinition),
new(RaceDefinition),
new(ClassDefinition),
new(MilestoneDefinition),
new(UnlockDefinition),
new(ReportReasonCategoryDefinition),
}
reader := NewTestReader()
manifest, err := NewManifest(reader)
if err != nil {
t.Fatal(err)
}
defer reader.Close()
for _, contract := range allContracts {
if err := manifest.FulfillContract(contract); err != nil {
t.Errorf("FulfillContract(%q): %v", contract.Name(), err)
}
}
}
// NewTestReader creates a ContractReader for testing.
func NewTestReader() *sqliteReader {
return &sqliteReader{cachedContracts: map[string][]byte{}}
}
// sqliteReader will implement ContractReader to allow contract fulfillment from a cached database.
type sqliteReader struct {
cachedContracts map[string][]byte
}
func (r *sqliteReader) ReadContract(contract Contract, path string, useMobile bool) ([]byte, error) {
name := contract.Name()
if !useMobile {
return ioutil.ReadFile(fmt.Sprintf("testdata/%s.json", contract.Name()))
}
if data, ok := r.cachedContracts[name]; ok {
return data, nil
}
data, err := readContractFromDB("testdata/mobile_manifest_en.sqlite", name)
if err != nil {
return nil, err
}
r.cachedContracts[name] = data
return data, nil
}
func (r *sqliteReader) Close() error {
r.cachedContracts = nil
return nil
}