-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathitems_test.go
102 lines (93 loc) · 2.44 KB
/
items_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
package steamapi
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestMockOkGetPlayerItems(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, GetMockOKGetPlayerItems())
}))
defer ts.Close()
BaseSteamAPIURL = ts.URL
appID := uint64(2)
steamID := uint64(1234)
apiKey := "123"
expectedPlayerItems := &Inventory{
Status: uint(1),
BackpackSlots: 840,
Items: []Item{
Item{
ID: uint64(1234567894),
OriginalID: uint64(123456),
Defindex: 5470,
Level: 1,
Quantity: 1,
Origin: 0,
Untradeable: false,
Uncraftable: false,
InventoryToken: uint32(19),
Quality: 4,
CustomName: "",
CustomDescription: "",
Attributes: []Attribute(nil),
Equipped: []EquipInfo{
EquipInfo{
Class: 23,
Slot: 6,
},
},
},
Item{
ID: uint64(1234567897),
OriginalID: uint64(1234567897),
Defindex: 5508,
Level: 1,
Quantity: 1,
Origin: 0,
Untradeable: true,
Uncraftable: false,
InventoryToken: uint32(25),
Quality: 4,
CustomName: "",
CustomDescription: "",
Attributes: []Attribute{
Attribute{
Defindex: 8,
Value: 1049511890,
FloatValue: 0.27789169549942017,
AccountInfo: (*AccountInfo)(nil),
},
Attribute{
Defindex: 9,
FloatValue: 0.2,
AccountInfo: (*AccountInfo)(nil),
},
},
},
},
}
playerItems, err := GetPlayerItems(steamID, appID, apiKey)
if err != nil {
t.Errorf("GetPlayerItems failure: %v", err)
return
}
// Is result marshallable?
_, err = json.Marshal(playerItems)
if err != nil {
t.Errorf("GetPlayerItems result marshalling failure: %v", err)
return
}
// Need a better test
if playerItems.Status != expectedPlayerItems.Status ||
playerItems.BackpackSlots != expectedPlayerItems.BackpackSlots ||
len(playerItems.Items) != len(expectedPlayerItems.Items) ||
playerItems.Items[1].Attributes[0].FloatValue != 0.27789169549942017 {
t.Errorf("GetPlayerItems(%v, %v, %v, %v) == %#v, expected %#v",
ts.URL, steamID, appID, apiKey, playerItems, expectedPlayerItems)
}
}