Skip to content

Commit 16a4cad

Browse files
authored
test: add a test case for object name compatibility (#16)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Tests** - Improved cleanup in object storage tests. - Added a test case for object name compatibility. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a4bf89b commit 16a4cad

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

test/OSSObject.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ describe('test/OSSObject.test.ts', () => {
485485
describe('put()', () => {
486486
let name: string;
487487
afterEach(async () => {
488-
await ossObject.delete(name);
488+
if (name) {
489+
await ossObject.delete(name);
490+
}
489491
});
490492

491493
it('should add object with local file path', async () => {
@@ -536,6 +538,40 @@ describe('test/OSSObject.test.ts', () => {
536538
assert.equal(object.name, name);
537539
});
538540

541+
it('should keep /foo/bar compatible to foo/bar', async () => {
542+
const name1 = `/${prefix}oss-client/oss/put-name-compatible`;
543+
const name2 = `${prefix}oss-client/oss/put-name-compatible`;
544+
const object1 = await ossObject.put(name1, Buffer.from('foo content'));
545+
assert.equal(typeof object1.res.headers['x-oss-request-id'], 'string');
546+
assert.equal(typeof object1.res.rt, 'number');
547+
assert.equal(object1.name, name2);
548+
let o = await ossObject.head(name1);
549+
assert(o);
550+
assert.equal(o.status, 200);
551+
await ossObject.delete(name1);
552+
await assert.rejects(async () => {
553+
await ossObject.head(name1);
554+
}, (err: any) => {
555+
assert.equal(err.code, 'NoSuchKey');
556+
return true;
557+
});
558+
559+
const object2 = await ossObject.put(name2, Buffer.from('foo content'));
560+
assert.equal(typeof object2.res.headers['x-oss-request-id'], 'string');
561+
assert.equal(typeof object2.res.rt, 'number');
562+
assert.equal(object2.name, name2);
563+
o = await ossObject.head(name2);
564+
assert(o);
565+
assert.equal(o.status, 200);
566+
await ossObject.delete(name2);
567+
await assert.rejects(async () => {
568+
await ossObject.head(name2);
569+
}, (err: any) => {
570+
assert.equal(err.code, 'NoSuchKey');
571+
return true;
572+
});
573+
});
574+
539575
it('should add object with readstream', async () => {
540576
name = `${prefix}oss-client/oss/put-readstream`;
541577
const object = await ossObject.put(name, createReadStream(__filename));

0 commit comments

Comments
 (0)