-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_test.go
executable file
·82 lines (75 loc) · 2.31 KB
/
account_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
package golink
import (
"bytes"
"code.google.com/p/go-etree"
"net/url"
"testing"
"time"
)
type apiTester string
func (r apiTester) Get(path string, params url.Values, c *APICredentials) (t etree.Element, err error) {
t, err = etree.Parse(bytes.NewBufferString(string(r)))
if err != nil {
return t, err
}
return t.Item(0), nil
}
func TestStatus(t *testing.T) {
a := NewCredentialedAPI(apiTester(statusXML), APICredentials{})
status, err := a.AccountStatus()
if err != nil {
t.Error(err)
}
if status != (aStatus{Paid: time.Unix(1293840000, 0).UTC(), Created: time.Unix(1072915200, 0).UTC(), Logins: 1234, MinutesPlayed: 9999}) {
t.Errorf("Wrong status returned. Got %+v", status)
}
}
func TestKeyInfo(t *testing.T) {
a := NewCredentialedAPI(apiTester(keyInfoXML), APICredentials{})
kinfo, err := a.AccountKeyInfo()
if err != nil {
t.Error(err)
}
x := time.Unix(1315699200, 0).UTC()
if kinfo.AccessMask != 59760264 || kinfo.Type != "char" || *kinfo.Expires != x || len(kinfo.Characters) != 1 || kinfo.Characters[898901870] != (aCharacter{Id: 898901870, Name: "Desmont McCallock", CorpId: 1000009, CorpName: "Caldari Provisions"}) {
t.Errorf("Wrong key info returned. Got %+v", kinfo)
}
}
func TestCharacters(t *testing.T) {
a := NewCredentialedAPI(apiTester(charactersXML), APICredentials{})
chars, err := a.AccountCharacters()
if err != nil {
t.Error(err)
}
if chars[1365215823] != (aCharacter{Id: 1365215823, Name: "Alexis Prey", CorpId: 238510404, CorpName: "Puppies To the Rescue"}) {
t.Errorf("Wrong character info returned. Got %+v", chars)
}
}
const (
statusXML = `
<result>
<paidUntil>2011-01-01 00:00:00</paidUntil>
<createDate>2004-01-01 00:00:00</createDate>
<logonCount>1234</logonCount>
<logonMinutes>9999</logonMinutes>
</result>
`
charactersXML = `
<result>
<rowset name="characters">
<row name="Alexis Prey" characterID="1365215823"
corporationName="Puppies To the Rescue" corporationID="238510404"/>
</rowset>
</result>
`
keyInfoXML = `
<result>
<key accessMask="59760264" type="Character" expires="2011-09-11 00:00:00">
<rowset name="characters">
<row characterID="898901870" characterName="Desmont McCallock"
corporationID="1000009" corporationName="Caldari Provisions" />
</rowset>
</key>
</result>
`
)