-
Notifications
You must be signed in to change notification settings - Fork 6
/
itchio_integration_test.go
181 lines (152 loc) · 4.5 KB
/
itchio_integration_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
package itchio
import (
"context"
"io/ioutil"
"net/http"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Integration(t *testing.T) {
apiKey := os.Getenv("ITCH_TEST_ACCOUNT_API_KEY")
if apiKey == "" {
t.Skipf("Skipping integration tests (no credentials)")
}
if testing.Short() {
t.Skipf("Skipping integration tests (short mode)")
}
ctx := context.Background()
{
t.Logf("Failing login")
c := ClientWithKey("<nope>")
res, err := c.LoginWithPassword(ctx, LoginWithPasswordParams{
Username: "itch-test-account",
Password: "nope",
})
if err == nil && res.RecaptchaNeeded {
t.Logf("Failing recaptcha...")
_, err = c.LoginWithPassword(ctx, LoginWithPasswordParams{
Username: "itch-test-account",
Password: "nope",
RecaptchaResponse: "oooh nope.",
})
}
assert.Error(t, err)
}
c := ClientWithKey(apiKey)
t.Logf("Retrieving profile...")
p, err := c.GetProfile(ctx)
assert.NoError(t, err)
assert.NotNil(t, p.User)
assert.EqualValues(t, "itch-test-account", p.User.Username)
t.Logf("Retrieving owned keys...")
ownedKeysRes, err := c.ListProfileOwnedKeys(ctx, ListProfileOwnedKeysParams{})
assert.NoError(t, err)
assert.NotEmpty(t, ownedKeysRes.OwnedKeys)
ownedKeysRes, err = c.ListProfileOwnedKeys(ctx, ListProfileOwnedKeysParams{
// if this tests ever breaks, we're doing well
Page: 200,
})
assert.NoError(t, err)
assert.Empty(t, ownedKeysRes.OwnedKeys)
var testCollID int64 = 105002
var testGameID int64 = 141753
t.Logf("Retrieving collection...")
collRes, err := c.GetCollection(ctx, GetCollectionParams{
CollectionID: testCollID,
})
assert.NoError(t, err)
assert.NotNil(t, collRes.Collection)
assert.NotEmpty(t, collRes.Collection.Title)
t.Logf("Retrieving collection games...")
collGamesRes, err := c.GetCollectionGames(ctx, GetCollectionGamesParams{
CollectionID: testCollID,
Page: 0,
})
assert.NoError(t, err)
assert.NotEmpty(t, collGamesRes.CollectionGames)
t.Logf("Retrieving game...")
g, err := c.GetGame(ctx, GetGameParams{
GameID: testGameID,
})
assert.NoError(t, err)
assert.NotNil(t, g.Game)
assert.EqualValues(t, "xna4-test", g.Game.Title)
assert.EqualValues(t, ArchitecturesAll, g.Game.Platforms.Windows)
assert.EqualValues(t, "", g.Game.Platforms.Linux)
t.Logf("Listing uploads...")
lu, err := c.ListGameUploads(ctx, ListGameUploadsParams{
GameID: testGameID,
})
assert.NoError(t, err)
assert.EqualValues(t, 1, len(lu.Uploads))
up := lu.Uploads[0]
assert.EqualValues(t, ArchitecturesAll, up.Platforms.Windows)
t.Logf("Listing builds for upload %d...", up.ID)
lb, err := c.ListUploadBuilds(ctx, ListUploadBuildsParams{
UploadID: up.ID,
})
assert.NoError(t, err)
assert.NotEmpty(t, 1, len(lb.Builds))
b := lb.Builds[0]
t.Logf("Downloading build %d", b.ID)
bURL := c.MakeBuildDownloadURL(MakeBuildDownloadURLParams{
BuildID: b.ID,
Type: BuildFileTypeArchive,
SubType: BuildFileSubTypeDefault,
})
download := func(url string) []byte {
req, err := http.NewRequest("GET", bURL, nil)
assert.NoError(t, err)
res, err := c.HTTPClient.Do(req)
assert.NoError(t, err)
assert.EqualValues(t, 200, res.StatusCode)
defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
assert.NoError(t, err)
return data
}
buildBytes := download(bURL)
assert.EqualValues(t, up.Size, len(buildBytes))
t.Logf("Listing build files for build %d", b.ID)
bf, err := c.ListBuildFiles(ctx, b.ID)
assert.NoError(t, err)
assert.NotEmpty(t, bf.Files)
var af *BuildFile
for _, f := range bf.Files {
if f.Type == BuildFileTypeArchive && f.SubType == BuildFileSubTypeDefault {
af = f
break
}
}
assert.NotNil(t, af)
t.Logf("Downloading archive-default build file for build %d", b.ID)
bfURL := c.MakeBuildFileDownloadURL(MakeBuildFileDownloadURLParams{
BuildID: b.ID,
FileID: af.ID,
})
buildFileBytes := download(bfURL)
assert.EqualValues(t, af.Size, len(buildFileBytes))
assert.EqualValues(t, buildBytes, buildFileBytes)
t.Logf("Looking for upgrade paths")
var oldBuild int64 = 64011
var newBuild int64 = 64020
pathRes, err := c.GetBuildUpgradePath(ctx, GetBuildUpgradePathParams{
CurrentBuildID: oldBuild,
TargetBuildID: newBuild,
})
assert.NoError(t, err)
assert.NotNil(t, pathRes.UpgradePath)
assert.NotEmpty(t, pathRes.UpgradePath.Builds)
var foundOld, foundNew bool
for _, b := range pathRes.UpgradePath.Builds {
if b.ID == oldBuild {
foundOld = true
}
if b.ID == newBuild {
foundNew = true
}
}
assert.True(t, foundOld)
assert.True(t, foundNew)
}