Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rm methods #8

Merged
merged 17 commits into from
Jan 9, 2023
Prev Previous commit
Next Next commit
fix(dir methods): rm
  • Loading branch information
korostelevm committed Jan 9, 2023
commit 892b388a0fcf5a73cf0ad14d6d3254a8561276b0
2 changes: 1 addition & 1 deletion src/CyclicS3FSPromises.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class CyclicS3FSPromises{

async rm(path){
try{
let f = await this.stat(path)
let f = await this.stat(path)
}catch(e){
throw e
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function makeCallback(cb) {
if (cb === undefined) {
return rethrow();
}

if (typeof cb !== 'function') {
throw new TypeError('callback must be a function');
}
Expand Down Expand Up @@ -102,6 +101,7 @@ class CyclicS3FS extends CyclicS3FSPromises {
callback = makeCallback(arguments[arguments.length - 1]);
new Promise(async (resolve,reject)=>{
try{
this.stat = super.stat
let res = await super.rm(...arguments)
return resolve(callback(null,res))
}catch(e){
Expand Down
60 changes: 60 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,66 @@ describe("Basic smoke tests", () => {
expect(contents).toEqual(['nested', 'file'])

})

test("rm() - promises", async () => {
const fs = s3fs_promises(BUCKET)
try{
await fs.rm('test/not_there.json')
}catch(e){
expect(e.message).toContain(`ENOENT: no such file or directory`)
}
await fs.writeFile('test/aaa.txt','asdfsdf')
await fs.rm('test/aaa.txt')

try{
await fs.stat('test/aaa.txt')
}catch(e){
expect(e.message).toContain(`ENOENT: no such file or directory`)
}
})

test("rmSync()", async () => {
const fs = s3fs(BUCKET)
try{
fs.rmSync('test/not_there.json')
}catch(e){
expect(e).toContain(`ENOENT: no such file or directory`)
}

fs.writeFileSync('test/aaa.txt','asdfsdf')
fs.rmSync('test/aaa.txt')

try{
await fs.statSync('test/aaa.txt')
}catch(e){
expect(e).toContain(`ENOENT: no such file or directory`)
}
})


test("rm() - callback", async () => {

const fs = s3fs(BUCKET)
await new Promise((resolve,reject)=>{
fs.rm('test/not_there.txt', (error,data) =>{
expect(error.message).toContain(`ENOENT: no such file or directory`)
resolve()
})
})
fs.writeFileSync('test/aaa.txt','asdfsdf')

await new Promise((resolve,reject)=>{
fs.rm('test/aaa.txt',(error,data)=>{
expect(error).toEqual(null)
resolve()
})
})




})




Expand Down