Skip to content

Commit 58284b0

Browse files
committed
test(downloader): prepare for an upcoming change
We are about to _always_ query the artifact metadata, even when not downloading the artifact but restoring it from the cache. Therefore, we need a fixture that artifact metadata. And since the logs of the original build are gone, we'll have to use a newer one. While at it, we already prepare the mocked `fetch()` to return the metadata in the second call. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 417a22d commit 58284b0

File tree

2 files changed

+184
-24
lines changed

2 files changed

+184
-24
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"Backoff",
99
"autodrain",
1010
"dpkg",
11+
"localpath",
1112
"refname",
1213
"unzipper",
1314
"vercel"

__tests__/downloader.test.ts

Lines changed: 183 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,214 @@ const buildIdResponse = {
66
count: 1,
77
value: [
88
{
9-
_links: [Object],
9+
_links: {
10+
self: {
11+
href:
12+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/Builds/73427'
13+
},
14+
web: {
15+
href:
16+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_build/results?buildId=73427'
17+
},
18+
sourceVersionDisplayUri: {
19+
href:
20+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/builds/73427/sources'
21+
},
22+
timeline: {
23+
href:
24+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/builds/73427/Timeline'
25+
},
26+
badge: {
27+
href:
28+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/status/22'
29+
}
30+
},
1031
properties: {},
1132
tags: [],
1233
validationResults: [],
13-
plans: [Array],
14-
triggerInfo: [Object],
15-
id: 71000,
16-
buildNumber: '71000',
34+
plans: [{planId: '294f4465-9475-43cd-a7f5-fb071dd52b25'}],
35+
triggerInfo: {
36+
'ci.sourceBranch': 'refs/heads/main',
37+
'ci.sourceSha': '2aa3bdf2c681810376f86dedd0b2f544b425eace',
38+
'ci.message': 'Update 6 packages',
39+
'ci.triggerRepository': 'git-for-windows/git-sdk-64'
40+
},
41+
id: 73427,
42+
buildNumber: '73427',
1743
status: 'completed',
1844
result: 'succeeded',
19-
queueTime: '2021-02-16T03:11:20.8026424Z',
20-
startTime: '2021-02-16T03:11:35.5385517Z',
21-
finishTime: '2021-02-16T03:42:07.4413436Z',
45+
queueTime: '2021-03-29T03:15:02.4106708Z',
46+
startTime: '2021-03-29T03:15:18.5120843Z',
47+
finishTime: '2021-03-29T03:49:59.8824069Z',
2248
url:
23-
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/Builds/71000',
24-
definition: [Object],
25-
project: [Object],
26-
uri: 'vstfs:///Build/Build/71000',
49+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/Builds/73427',
50+
definition: {
51+
drafts: [],
52+
id: 22,
53+
name: 'git-sdk-64-minimal',
54+
url:
55+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/Definitions/22?revision=42',
56+
uri: 'vstfs:///Build/Definition/22',
57+
path: '\\',
58+
type: 'build',
59+
queueStatus: 'enabled',
60+
revision: 42,
61+
project: {
62+
id: 'f3317b6a-fa67-40d4-9a33-b652e06943df',
63+
name: 'git',
64+
description: 'Git for Windows',
65+
url:
66+
'https://dev.azure.com/Git-for-Windows/_apis/projects/f3317b6a-fa67-40d4-9a33-b652e06943df',
67+
state: 'wellFormed',
68+
revision: 58,
69+
visibility: 'public',
70+
lastUpdateTime: '2018-05-01T10:31:00.293Z'
71+
}
72+
},
73+
project: {
74+
id: 'f3317b6a-fa67-40d4-9a33-b652e06943df',
75+
name: 'git',
76+
description: 'Git for Windows',
77+
url:
78+
'https://dev.azure.com/Git-for-Windows/_apis/projects/f3317b6a-fa67-40d4-9a33-b652e06943df',
79+
state: 'wellFormed',
80+
revision: 58,
81+
visibility: 'public',
82+
lastUpdateTime: '2018-05-01T10:31:00.293Z'
83+
},
84+
uri: 'vstfs:///Build/Build/73427',
2785
sourceBranch: 'refs/heads/main',
28-
sourceVersion: 'c1d940ae0b2de75e18f642e76750f19b0f92dbc6',
86+
sourceVersion: '2aa3bdf2c681810376f86dedd0b2f544b425eace',
2987
priority: 'normal',
3088
reason: 'individualCI',
31-
requestedFor: [Object],
32-
requestedBy: [Object],
33-
lastChangedDate: '2021-02-16T03:42:07.653Z',
34-
lastChangedBy: [Object],
35-
orchestrationPlan: [Object],
36-
logs: [Object],
37-
repository: [Object],
89+
requestedFor: {
90+
displayName: 'Microsoft.VisualStudio.Services.TFS',
91+
url:
92+
'https://spsprodcus1.vssps.visualstudio.com/A7ef732d2-e7e4-499c-8f88-7ee74b5c51cc/_apis/Identities/00000002-0000-8888-8000-000000000000',
93+
_links: {
94+
avatar: {
95+
href:
96+
'https://dev.azure.com/Git-for-Windows/_apis/GraphProfile/MemberAvatars/s2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA'
97+
}
98+
},
99+
id: '00000002-0000-8888-8000-000000000000',
100+
uniqueName: null,
101+
imageUrl: null,
102+
descriptor:
103+
's2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA'
104+
},
105+
requestedBy: {
106+
displayName: 'Microsoft.VisualStudio.Services.TFS',
107+
url:
108+
'https://spsprodcus1.vssps.visualstudio.com/A7ef732d2-e7e4-499c-8f88-7ee74b5c51cc/_apis/Identities/00000002-0000-8888-8000-000000000000',
109+
_links: {
110+
avatar: {
111+
href:
112+
'https://dev.azure.com/Git-for-Windows/_apis/GraphProfile/MemberAvatars/s2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA'
113+
}
114+
},
115+
id: '00000002-0000-8888-8000-000000000000',
116+
uniqueName: null,
117+
imageUrl: null,
118+
descriptor:
119+
's2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA'
120+
},
121+
lastChangedDate: '2021-03-29T03:50:00.2Z',
122+
lastChangedBy: {
123+
displayName: 'Microsoft.VisualStudio.Services.TFS',
124+
url:
125+
'https://spsprodcus1.vssps.visualstudio.com/A7ef732d2-e7e4-499c-8f88-7ee74b5c51cc/_apis/Identities/00000002-0000-8888-8000-000000000000',
126+
_links: {
127+
avatar: {
128+
href:
129+
'https://dev.azure.com/Git-for-Windows/_apis/GraphProfile/MemberAvatars/s2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA'
130+
}
131+
},
132+
id: '00000002-0000-8888-8000-000000000000',
133+
uniqueName: null,
134+
imageUrl: null,
135+
descriptor:
136+
's2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA'
137+
},
138+
orchestrationPlan: {planId: '294f4465-9475-43cd-a7f5-fb071dd52b25'},
139+
logs: {
140+
id: 0,
141+
type: 'Container',
142+
url:
143+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/builds/73427/logs'
144+
},
145+
repository: {
146+
id: 'git-for-windows/git-sdk-64',
147+
type: 'GitHub',
148+
clean: null,
149+
checkoutSubmodules: false
150+
},
38151
keepForever: true,
39152
retainedByRelease: false,
40153
triggeredByBuild: null
41154
}
42155
]
43156
}
44157

158+
const artifactResponse = {
159+
count: 2,
160+
value: [
161+
{
162+
id: 12184,
163+
name: 'git-artifacts',
164+
source: 'fd490c07-0b22-5182-fac9-6d67fe1e939b',
165+
resource: {
166+
type: 'PipelineArtifact',
167+
data:
168+
'A7DC9A9D5763E9B7A287E22EBE4BBE297B74AAC544823A86AD215C0D9A8EEDD001',
169+
properties: {
170+
RootId:
171+
'B1146F8C4772281CA63EA26BE97329B69A740CA21B7C3B8B74AFE4BEE9B30DE902',
172+
artifactsize: '49185757'
173+
},
174+
url:
175+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/builds/73427/artifacts?artifactName=git-artifacts&api-version=6.0',
176+
downloadUrl:
177+
'https://artprodcus3.artifacts.visualstudio.com/Ac037a06e-1e3b-41a1-b045-ce593a4d2ab4/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL0dpdC1mb3ItV2luZG93cy9wcm9qZWN0SWQvZjMzMTdiNmEtZmE2Ny00MGQ0LTlhMzMtYjY1MmUwNjk0M2RmL2J1aWxkSWQvNzM0MjcvYXJ0aWZhY3ROYW1lL2dpdC1hcnRpZmFjdHM1/content?format=zip'
178+
}
179+
},
180+
{
181+
id: 12185,
182+
name: 'git-sdk-64-minimal',
183+
source: 'fd490c07-0b22-5182-fac9-6d67fe1e939b',
184+
resource: {
185+
type: 'Container',
186+
data: '#/15737294/git-sdk-64-minimal',
187+
properties: {
188+
localpath: 'D:\\a\\1\\s\\git-sdk-64-minimal',
189+
artifactsize: '249437960'
190+
},
191+
url:
192+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/builds/73427/artifacts?artifactName=git-sdk-64-minimal&api-version=6.0',
193+
downloadUrl:
194+
'https://dev.azure.com/Git-for-Windows/f3317b6a-fa67-40d4-9a33-b652e06943df/_apis/build/builds/73427/artifacts?artifactName=git-sdk-64-minimal&api-version=6.0&%24format=zip'
195+
}
196+
}
197+
]
198+
}
199+
45200
jest.mock('node-fetch')
46201
const {Response} = jest.requireActual('node-fetch')
47202

48203
test('can obtain build ID', async () => {
49-
mocked(fetch).mockReturnValue(
50-
Promise.resolve(new Response(JSON.stringify(buildIdResponse)))
51-
)
204+
mocked(fetch)
205+
.mockReturnValueOnce(
206+
Promise.resolve(new Response(JSON.stringify(buildIdResponse)))
207+
)
208+
.mockReturnValueOnce(
209+
Promise.resolve(new Response(JSON.stringify(artifactResponse)))
210+
)
52211
const {cacheId} = await get(
53212
'git-for-windows/git',
54213
'22',
55214
'git-sdk-64-minimal',
56215
undefined
57216
)
58217
expect(fetch).toHaveBeenCalledTimes(1)
59-
expect(cacheId).toEqual('git-for-windows.git-22-git-sdk-64-minimal-71000')
218+
expect(cacheId).toEqual('git-for-windows.git-22-git-sdk-64-minimal-73427')
60219
})

0 commit comments

Comments
 (0)