| 201 | |
| 202 | class MetadataMock { |
| 203 | onRequest(req, res) { |
| 204 | if (req.method !== 'GET') { |
| 205 | res.writeHead(501); |
| 206 | return res.end(JSON.stringify({ |
| 207 | error: 'mock server only supports GET requests', |
| 208 | })); |
| 209 | } |
| 210 | if (/\/_\/raft_sessions\/[1-8]\/bucket/.test(req.url)) { |
| 211 | const value = ['bucket1', 'bucket2', 'users..bucket']; |
| 212 | res.writeHead(200, { 'content-type': 'application/json' }); |
| 213 | return res.end(JSON.stringify(value)); |
| 214 | } else if (/\/default\/attributes\/[a-z0-9]/.test(req.url)) { |
| 215 | const bucketName = req.url.split('/'); |
| 216 | const bucketMd = dummyBucketMD[bucketName[bucketName.length - 1]]; |
| 217 | const dummyBucketMdObj = new BucketInfo(bucketMd._name, |
| 218 | bucketMd._owner, bucketMd._ownerDisplayName, |
| 219 | bucketMd._creationDate, bucketMd._mdBucketModelVersion, |
| 220 | bucketMd._acl, bucketMd._transient, bucketMd._deleted, |
| 221 | bucketMd._serverSideEncryption, |
| 222 | bucketMd.versioningConfiguration, bucketMd._locationContraint, |
| 223 | bucketMd._websiteConfiguration, bucketMd._cors, |
| 224 | bucketMd._lifeCycle); |
| 225 | return res.end(dummyBucketMdObj.serialize()); |
| 226 | } else if |
| 227 | (/\/default\/bucket\/.*?listingType=Delimiter/.test(req.url)) { |
| 228 | return res.end(JSON.stringify(objectList)); |
| 229 | } else if (/\/default\/bucket\/.*\/.*?/.test(req.url)) { |
| 230 | return res.end(JSON.stringify({ |
| 231 | 'owner-id': '123', |
| 232 | 'metadata': 'dogsAreGood', |
| 233 | })); |
| 234 | } else if (mockLogURLRegex.test(req.url)) { |
| 235 | return res.end(JSON.stringify(mockLogs)); |
| 236 | } |
| 237 | res.writeHead(404); |
| 238 | return res.end(JSON.stringify({ |
| 239 | error: 'invalid path', |
| 240 | })); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | module.exports = MetadataMock; |