-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -476,6 +476,111 @@ describe('Storage test', () => { | |
assert.deepEqual(puts.r2, expectedPuts); | ||
}); | ||
|
||
it('can copy objects and add metadata', async () => { | ||
const listReply = JSON.parse(await fs.readFile(path.resolve(__testdir, 'fixtures', 'list-reply-copy.json'), 'utf-8')); | ||
const puts = { s3: [], r2: [] }; | ||
const putsHeaders = { s3: [], r2: [] }; | ||
const heads = []; | ||
nock('https://helix-code-bus.s3.fake.amazonaws.com') | ||
.get('/?list-type=2&prefix=owner%2Frepo%2Fref%2F') | ||
.reply(200, listReply[0]) | ||
.get('/?continuation-token=1%2Fs4dr7BSKNScrN4njX9%2BCpBNimYkuEzMWg3niTSAPMdculBmycyUPM6kv0xi46j4hdc1lFPkE%2FICI8TxG%2BVNV9Hh91Ou0hqeBYzqTRzSBSs%3D&list-type=2&prefix=owner%2Frepo%2Fref%2F') | ||
.reply(200, listReply[1]) | ||
.head(/.*/) | ||
.times(10) | ||
.reply((uri) => { | ||
heads.push(uri); | ||
// reject first uri | ||
if (puts.s3.length === 1) { | ||
return [404]; | ||
} | ||
return [200, undefined, { | ||
'x-amz-meta-x-dont-overwrite': 'foo', | ||
'x-amz-meta-x-last-modified-by': 'anonymous', | ||
}]; | ||
}) | ||
.put(/.*/) | ||
.times(10) | ||
.reply(function f(uri) { | ||
puts.s3.push(uri); | ||
putsHeaders.s3.push({ | ||
'x-amz-metadata-directive': this.req.headers['x-amz-metadata-directive'], | ||
'x-amz-meta-x-dont-overwrite': this.req.headers['x-amz-meta-x-dont-overwrite'], | ||
'x-amz-meta-x-last-modified-by': this.req.headers['x-amz-meta-x-last-modified-by'], | ||
}); | ||
// reject first uri | ||
if (puts.s3.length === 1) { | ||
return [404]; | ||
} | ||
return [200, '<?xml version="1.0" encoding="UTF-8"?>\n<CopyObjectResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LastModified>2021-05-05T08:37:23.000Z</LastModified><ETag>"f278c0035a9b4398629613a33abe6451"</ETag></CopyObjectResult>']; | ||
}); | ||
nock(`https://helix-code-bus.${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`) | ||
.put(/.*/) | ||
.times(10) | ||
.reply(function f(uri) { | ||
puts.r2.push(uri); | ||
putsHeaders.r2.push({ | ||
'x-amz-metadata-directive': this.req.headers['x-amz-metadata-directive'], | ||
'x-amz-meta-x-dont-overwrite': this.req.headers['x-amz-meta-x-dont-overwrite'], | ||
'x-amz-meta-x-last-modified-by': this.req.headers['x-amz-meta-x-last-modified-by'], | ||
}); | ||
// reject first uri | ||
if (puts.s3.length === 1) { | ||
return [404]; | ||
} | ||
return [200, '<?xml version="1.0" encoding="UTF-8"?>\n<CopyObjectResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LastModified>2021-05-05T08:37:23.000Z</LastModified><ETag>"f278c0035a9b4398629613a33abe6451"</ETag></CopyObjectResult>']; | ||
}); | ||
|
||
const bus = storage.codeBus(); | ||
await bus.copyDeep('/owner/repo/ref/', '/bar/', undefined, { addMetadata: { 'x-last-modified-by': '[email protected]' } }); | ||
|
||
puts.s3.sort(); | ||
puts.r2.sort(); | ||
heads.sort(); | ||
|
||
assert.strictEqual(putsHeaders.s3.length, 10); | ||
assert.strictEqual(putsHeaders.r2.length, 10); | ||
|
||
Object.values(putsHeaders).forEach((s3r2) => { | ||
s3r2.forEach((headers) => { | ||
assert.deepEqual(headers, { | ||
'x-amz-meta-x-dont-overwrite': 'foo', | ||
'x-amz-meta-x-last-modified-by': '[email protected]', | ||
'x-amz-metadata-directive': 'REPLACE', | ||
}); | ||
}); | ||
}); | ||
|
||
const expectedHeads = [ | ||
'/owner/repo/ref/.circleci/config.yml', | ||
'/owner/repo/ref/.gitignore', | ||
'/owner/repo/ref/.vscode/launch.json', | ||
'/owner/repo/ref/.vscode/settings.json', | ||
'/owner/repo/ref/README.md', | ||
'/owner/repo/ref/helix_logo.png', | ||
'/owner/repo/ref/htdocs/favicon.ico', | ||
'/owner/repo/ref/htdocs/style.css', | ||
'/owner/repo/ref/index.md', | ||
'/owner/repo/ref/src/html.pre.js', | ||
]; | ||
assert.deepEqual(heads, expectedHeads); | ||
|
||
const expectedPuts = [ | ||
'/bar/.circleci/config.yml?x-id=CopyObject', | ||
'/bar/.gitignore?x-id=CopyObject', | ||
'/bar/.vscode/launch.json?x-id=CopyObject', | ||
'/bar/.vscode/settings.json?x-id=CopyObject', | ||
'/bar/README.md?x-id=CopyObject', | ||
'/bar/helix_logo.png?x-id=CopyObject', | ||
'/bar/htdocs/favicon.ico?x-id=CopyObject', | ||
'/bar/htdocs/style.css?x-id=CopyObject', | ||
'/bar/index.md?x-id=CopyObject', | ||
'/bar/src/html.pre.js?x-id=CopyObject', | ||
]; | ||
assert.deepEqual(puts.s3, expectedPuts); | ||
assert.deepEqual(puts.r2, expectedPuts); | ||
}); | ||
|
||
it('can copy object (non deep)', async () => { | ||
const puts = { s3: [], r2: [] }; | ||
nock('https://helix-code-bus.s3.fake.amazonaws.com') | ||
|
@@ -503,6 +608,60 @@ describe('Storage test', () => { | |
assert.deepEqual(puts.r2, expectedPuts); | ||
}); | ||
|
||
it('can copy object, and add metadata (non deep)', async () => { | ||
const puts = { s3: [], r2: [] }; | ||
const putsHeaders = { s3: undefined, r2: undefined }; | ||
nock('https://helix-code-bus.s3.fake.amazonaws.com') | ||
.head('/owner/repo/ref/foo.md') | ||
.reply(200, undefined, { | ||
'x-amz-meta-x-dont-overwrite': 'foo', | ||
'x-amz-meta-x-last-modified-by': 'anonymous', | ||
}) | ||
.put('/owner/repo/ref/foo/bar.md?x-id=CopyObject') | ||
.reply(function f(uri) { | ||
putsHeaders.s3 = { | ||
'x-amz-metadata-directive': this.req.headers['x-amz-metadata-directive'], | ||
'x-amz-meta-x-dont-overwrite': this.req.headers['x-amz-meta-x-dont-overwrite'], | ||
'x-amz-meta-x-last-modified-by': this.req.headers['x-amz-meta-x-last-modified-by'], | ||
}; | ||
puts.s3.push(uri); | ||
return [200, '<?xml version="1.0" encoding="UTF-8"?>\n<CopyObjectResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LastModified>2021-05-05T08:37:23.000Z</LastModified><ETag>"f278c0035a9b4398629613a33abe6451"</ETag></CopyObjectResult>']; | ||
}); | ||
nock(`https://helix-code-bus.${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`) | ||
.put('/owner/repo/ref/foo/bar.md?x-id=CopyObject') | ||
.reply(function f(uri) { | ||
putsHeaders.r2 = { | ||
'x-amz-metadata-directive': this.req.headers['x-amz-metadata-directive'], | ||
'x-amz-meta-x-dont-overwrite': this.req.headers['x-amz-meta-x-dont-overwrite'], | ||
'x-amz-meta-x-last-modified-by': this.req.headers['x-amz-meta-x-last-modified-by'], | ||
}; | ||
puts.r2.push(uri); | ||
return [200, '<?xml version="1.0" encoding="UTF-8"?>\n<CopyObjectResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LastModified>2021-05-05T08:37:23.000Z</LastModified><ETag>"f278c0035a9b4398629613a33abe6451"</ETag></CopyObjectResult>']; | ||
}); | ||
|
||
const bus = storage.codeBus(); | ||
await bus.copy('/owner/repo/ref/foo.md', '/owner/repo/ref/foo/bar.md', { addMetadata: { 'x-last-modified-by': '[email protected]' } }); | ||
|
||
puts.s3.sort(); | ||
puts.r2.sort(); | ||
const expectedPuts = [ | ||
'/owner/repo/ref/foo/bar.md?x-id=CopyObject', | ||
]; | ||
assert.deepEqual(puts.s3, expectedPuts); | ||
assert.deepEqual(puts.r2, expectedPuts); | ||
|
||
assert.deepEqual(putsHeaders.s3, { | ||
'x-amz-metadata-directive': 'REPLACE', | ||
'x-amz-meta-x-dont-overwrite': 'foo', | ||
'x-amz-meta-x-last-modified-by': '[email protected]', | ||
}); | ||
assert.deepEqual(putsHeaders.r2, { | ||
'x-amz-metadata-directive': 'REPLACE', | ||
'x-amz-meta-x-dont-overwrite': 'foo', | ||
'x-amz-meta-x-last-modified-by': '[email protected]', | ||
}); | ||
}); | ||
|
||
it('can copy object can fail (non deep)', async () => { | ||
nock('https://helix-code-bus.s3.fake.amazonaws.com') | ||
.put('/owner/repo/ref/foo/bar.md?x-id=CopyObject') | ||
|