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

Error calling emptyBucket function. #9

Closed
xavier-thomas opened this issue Oct 28, 2020 · 6 comments · Fixed by #11
Closed

Error calling emptyBucket function. #9

xavier-thomas opened this issue Oct 28, 2020 · 6 comments · Fixed by #11
Assignees
Labels
bug Something isn't working

Comments

@xavier-thomas
Copy link
Owner

SUMMARY

When invoking the lambda against a bucket, it throws the following error
Error during Cleanup - TypeError: Cannot read property 'emptyBucket' of undefined

ISSUE TYPE
  • Bug Report
VERSIONS
v1.1.1 and v1.1.0
STEPS TO REPRODUCE
  • Deploy the lambda from SAR
  • Invoke the lambda from cloud formation
  • Bucket to delete needs to have content, so that the empty bucket function is called.
@xavier-thomas xavier-thomas added the bug Something isn't working label Oct 28, 2020
@xavier-thomas
Copy link
Owner Author

@mfarrow701 Believe this is due to the use of this.emptyBucket()

https://github.com/xavier-thomas/aws-cfn-stack-cleanup/blob/master/src/s3.js#L63

Any alternatives here ?

@mfarrow701
Copy link
Collaborator

@mfarrow701 Believe this is due to the use of this.emptyBucket()

https://github.com/xavier-thomas/aws-cfn-stack-cleanup/blob/master/src/s3.js#L63

Any alternatives here ?

@xavier-thomas
You can call await emptyBucket(srcBucket) (line 68), and remove the function parameter _emptyBucket = this.emptyBucket, no?

@xavier-thomas
Copy link
Owner Author

emptyBucket(srcBucket)

Because we are exporting export const emptyBucket, I don't believe it allows you to call it as a function.

@mfarrow701
Copy link
Collaborator

emptyBucket(srcBucket)

Because we are exporting export const emptyBucket, I don't believe it allows you to call it as a function.

@xavier-thomas, sure you can 😉 The export keyword just allows you to import, read or call the method from another module.

@xavier-thomas
Copy link
Owner Author

xavier-thomas commented Oct 29, 2020

emptyBucket(srcBucket)

Because we are exporting export const emptyBucket, I don't believe it allows you to call it as a function.

@xavier-thomas, sure you can 😉 The export keyword just allows you to import, read or call the method from another module.

And what's the best way of mocking this in the tests ? Since the tests are testing both functions separately. I need to mock the resolved value of emptyBucket() when called by the deleteBucket(). But the actual tests for the emptyBucket() should not mock the call.

I realise that I can mock all the api calls, but I would rather test each function in isolation.

@xavier-thomas xavier-thomas linked a pull request Oct 29, 2020 that will close this issue
1 task
@xavier-thomas xavier-thomas linked a pull request Nov 16, 2020 that will close this issue
1 task
@xavier-thomas
Copy link
Owner Author

@mfarrow701 Didn't have a lot of time to try the JS classes. Went instead with your option of splitting the modules. #11

This should get it working (🤞) , but feel free to try the class approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants