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

aws mock s3 putObjectTagging "Not Working" ISSUE / Bug #266

Open
1 task
hanoj-budime opened this issue Mar 23, 2022 · 11 comments
Open
1 task

aws mock s3 putObjectTagging "Not Working" ISSUE / Bug #266

hanoj-budime opened this issue Mar 23, 2022 · 11 comments
Labels
help wanted If you can help make progress with this issue, please comment! technical A technical issue that requires understanding of the code, infrastructure or dependencies

Comments

@hanoj-budime
Copy link

hanoj-budime commented Mar 23, 2022

! important

S3 putObjectTagging mock not working, why any ideas..... ???


look.test.js

const AWS = require("aws-sdk-mock");

describe('s3 putObjectTagging', () => {
...
    beforeAll(async () => {
         // Arrange
        AWS.mock("S3", "putObjectTagging", jest.fn((params, callback) => {  // Not working
          callback(null, {});
        }));
      ....
    });
    ....
    // Assert
    ....
});

package.json

"dependencies": {
    "aws-sdk-mock": "^5.6.2", // aws-sdk mock
    "jest": "^27.5.1",
    "jest-junit": "^13.0.0",
    "jest-runner-eslint": "^1.0.0"
  }
@nelsonic nelsonic added help wanted If you can help make progress with this issue, please comment! technical A technical issue that requires understanding of the code, infrastructure or dependencies labels Mar 23, 2022
@nelsonic
Copy link
Member

@HanojHanu what are you seeing when you attempt to run this code? (what is the output?)

@hanoj-budime
Copy link
Author

hanoj-budime commented Mar 23, 2022

@HanojHanu what are you seeing when you attempt to run this code? (what is the output?)

Not Mocking my code in Jest using Nodejs

  • Failed to tag the requested S3 Object
  • Unhandled error. (NoSuchBucket: The specified bucket does not exist

Terminal

Test suite failed to run

    Error [ERR_UNHANDLED_ERROR]: Unhandled error. (NoSuchBucket: The specified bucket does not exist
      at Request.extractError (node_modules/aws-sdk/lib/services/s3.js:710:35)
      at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:106:20)
      at Request.emit (node_modules/aws-sdk/lib/sequential_executor.js:78:10)
      at Request.emit (node_modules/aws-sdk/lib/request.js:686:14)
      at Request.transition (node_modules/aws-sdk/lib/request.js:22:10)
      at AcceptorStateMachine.runTo (node_modules/aws-sdk/lib/state_machine.js:14:12)
      at node_modules/aws-sdk/lib/state_machine.js:26:10
      at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:38:9)
      at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:688:12)
      at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
        code: 'NoSuchBucket',
        region: null,
        time: 2022-03-24T04:04:56.504Z,
        requestId: 'AASKZ3Q97T6P1XCV',
        extendedRequestId: 'wId6kZvnmgMk9LIL+Ll2iVGjqKHiaOsLzgDPdzyXnwbN1cY1po1+wGLy7BLWYcDOrcquauHxN/s=',
        cfId: undefined,
        statusCode: 404,
        retryable: false,
        retryDelay: 92.723206311658
      })
      at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:590:14)
      at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:106:20)
      at Request.emit (node_modules/aws-sdk/lib/sequential_executor.js:78:10)
      at Request.emit (node_modules/aws-sdk/lib/request.js:686:14)
      at Request.transition (node_modules/aws-sdk/lib/request.js:22:10)
      at AcceptorStateMachine.runTo (node_modules/aws-sdk/lib/state_machine.js:14:12)
      at node_modules/aws-sdk/lib/state_machine.js:26:10
      at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:38:9)

@hanoj-budime hanoj-budime changed the title aws mock s3 putObjectTagging "Not Working" aws mock s3 putObjectTagging "Not Working" ISSUE / Bug Mar 23, 2022
@hanoj-budime
Copy link
Author

hanoj-budime commented Mar 24, 2022

@nelsonic Any updates on this issue ?

@hanoj-budime
Copy link
Author

@nelsonic @thomaux

@nelsonic
Copy link
Member

@HanojHanu the stack trace you've shared above is for aws-sdk ... You're getting an error when using the actual SDK.

@thomaux
Copy link
Collaborator

thomaux commented Mar 25, 2022

Hey @HanojHanu, this might be related to how your actual code is initialised. For example, if S3 is initialised at the top of your module, aws-sdk-mock cannot mock it. Try adding the following to your tests:

beforeEach(() => {
	// import the aws-sdk after the resetModules, but before each test.
	jest.resetModules();
	AWSMock.setSDKInstance(require('aws-sdk'));
        AWSMock.mock("S3", "putObjectTagging", jest.fn((params, callback) => {  // Not working
          callback(null, {});
        }));
});

afterEach(() => {
    AWSMock.restore();
});

@hanoj-budime
Copy link
Author

Hey @HanojHanu, this might be related to how your actual code is initialised. For example, if S3 is initialised at the top of your module, aws-sdk-mock cannot mock it. Try adding the following to your tests:

beforeEach(() => {
	// import the aws-sdk after the resetModules, but before each test.
	jest.resetModules();
	AWSMock.setSDKInstance(require('aws-sdk'));
        AWSMock.mock("S3", "putObjectTagging", jest.fn((params, callback) => {  // Not working
          callback(null, {});
        }));
});

afterEach(() => {
    AWSMock.restore();
});

Thanks @thomaux, I'll try this.

I'll update here..

@hanoj-budime
Copy link
Author

hanoj-budime commented Mar 25, 2022

tried the same way, what you suggested. @thomaux
But still the same error.
#266 (comment)

@hanoj-budime
Copy link
Author

https://stackblitz.com/edit/node-as6ark?file=index.test.js

@thomaux , @nelsonic

@thomaux
Copy link
Collaborator

thomaux commented Mar 29, 2022

Thanks @HanojHanu that's useful. I'll take some time later this week to take a look at what's going wrong. From the sources I can tell that S3 is being initialised at the top of the file, which is most likely causing the issue.

@hanoj-budime
Copy link
Author

Any Fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted If you can help make progress with this issue, please comment! technical A technical issue that requires understanding of the code, infrastructure or dependencies
Projects
None yet
Development

No branches or pull requests

3 participants