Remove dependency
This commit is contained in:
Generated
-1369
File diff suppressed because it is too large
Load Diff
@@ -78,7 +78,6 @@
|
|||||||
"concurrently": "^5.0.0",
|
"concurrently": "^5.0.0",
|
||||||
"eslint": "^10.0.3",
|
"eslint": "^10.0.3",
|
||||||
"eslint-plugin-compat": "^7.0.1",
|
"eslint-plugin-compat": "^7.0.1",
|
||||||
"fauxqs": "^2.3.1",
|
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"husky": "^3.1.0",
|
"husky": "^3.1.0",
|
||||||
"lint-staged": "^16.3.2",
|
"lint-staged": "^16.3.2",
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
const http = require('http');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimal in-memory S3-compatible server for testing.
|
||||||
|
* Supports PutObject and GetObject via path-style requests.
|
||||||
|
*/
|
||||||
|
function createFakeS3() {
|
||||||
|
const buckets = new Map();
|
||||||
|
|
||||||
|
const server = http.createServer((req, res) => {
|
||||||
|
const { bucket, key } = parsePath(req.url);
|
||||||
|
|
||||||
|
if (!bucket || !buckets.has(bucket)) {
|
||||||
|
res.writeHead(404, { 'Content-Type': 'application/xml' });
|
||||||
|
res.end('<Error><Code>NoSuchBucket</Code></Error>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = buckets.get(bucket);
|
||||||
|
|
||||||
|
if (req.method === 'PUT' && key) {
|
||||||
|
const chunks = [];
|
||||||
|
req.on('data', (chunk) => chunks.push(chunk));
|
||||||
|
req.on('end', () => {
|
||||||
|
store.set(key, Buffer.concat(chunks));
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
} else if ((req.method === 'GET' || req.method === 'HEAD') && key) {
|
||||||
|
if (!store.has(key)) {
|
||||||
|
res.writeHead(404, { 'Content-Type': 'application/xml' });
|
||||||
|
res.end('<Error><Code>NoSuchKey</Code></Error>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const body = store.get(key);
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Length': body.length,
|
||||||
|
'Content-Type': 'application/octet-stream',
|
||||||
|
});
|
||||||
|
res.end(req.method === 'HEAD' ? undefined : body);
|
||||||
|
} else {
|
||||||
|
res.writeHead(405);
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
start() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
server.listen(0, '127.0.0.1', () => {
|
||||||
|
const { port } = server.address();
|
||||||
|
resolve({
|
||||||
|
address: `http://127.0.0.1:${port}`,
|
||||||
|
createBucket(name) {
|
||||||
|
if (!buckets.has(name)) buckets.set(name, new Map());
|
||||||
|
},
|
||||||
|
reset() {
|
||||||
|
for (const store of buckets.values()) store.clear();
|
||||||
|
},
|
||||||
|
stop() {
|
||||||
|
return new Promise((r) => server.close(r));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parsePath(url) {
|
||||||
|
// Path-style: /<bucket>/<key>
|
||||||
|
const parts = new URL(url, 'http://localhost').pathname
|
||||||
|
.replace(/^\//, '')
|
||||||
|
.split('/');
|
||||||
|
return {
|
||||||
|
bucket: parts[0] || null,
|
||||||
|
key: parts.slice(1).join('/') || null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { createFakeS3 };
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { S3, GetObjectCommand } = require('@aws-sdk/client-s3');
|
const { S3, GetObjectCommand } = require('@aws-sdk/client-s3');
|
||||||
|
const { createFakeS3 } = require('./fake-s3');
|
||||||
|
|
||||||
const BUCKET = 'test-bucket';
|
const BUCKET = 'test-bucket';
|
||||||
|
|
||||||
@@ -12,13 +13,11 @@ const {
|
|||||||
getLocalFile,
|
getLocalFile,
|
||||||
} = require('../publish-to-aws');
|
} = require('../publish-to-aws');
|
||||||
|
|
||||||
let startFauxqs;
|
|
||||||
let server;
|
let server;
|
||||||
let s3Client;
|
let s3Client;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
({ startFauxqs } = await import('fauxqs'));
|
server = await createFakeS3().start();
|
||||||
server = await startFauxqs({ port: 0, logger: false });
|
|
||||||
server.createBucket(BUCKET);
|
server.createBucket(BUCKET);
|
||||||
|
|
||||||
s3Client = new S3({
|
s3Client = new S3({
|
||||||
|
|||||||
Reference in New Issue
Block a user