Git Product home page Git Product logo

mock-aws-sdk-js's People

Contributors

ian29 avatar rclark avatar tmcw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mock-aws-sdk-js's Issues

Upgrade to sinon 2.x

looking at #4 shows that upgrading to sinon 2.x will give the AWS stubs a few more methods useful for testing. This hopefully isn't a huge lift, and should result in mostly updating the stub call to use the callsFake method.

cc @rclark @GretaCB @millzpaugh

Upgrade sinon.js

Sinon is up in the v4.x territory now. Upgrading would make it easier to read sinon docs to understand how to use the stubs that this library creates.

Since this library returns sinon stubs and since that lib has gone through major version upgrades, making this change should increment the major version here as well.

Feature request: the ability to restore all services at once.

First of all thanks for this, it's been really handy.

I expect my tests to be independent from each other, and also to not need to cleanup after themselves. Given this, I'd like to call a single AWS.restore() (or similar) after each test runs.

Would you be interested in a PR with such a function?

Any suggestions on how you'd like to see it work? I was thinking a list of services could be maintained when stubbing, then it'd be easy enough to iterate through these calling .restore(), but I'm happy to defer to your judgment.

Mocking two SQS calls

Is there a way to run the same stub twice, but with different specifications? (ie There are two calls to two different SQS queues with different responses for each queue.)

Example code:

  var q = d3.queue(5);
  q.defer(getInfo, QueueUrl);
  q.defer(getInfo, QueueUrl);
  q.await(function(err, main, dl) {
    if (err) return callback(err);
    console.log(dl.Attributes.ApproximateNumberOfMessages)
    if (+dl.Attributes.ApproximateNumberOfMessages === 0) return callback(null);

    var message = 'Queue stats:\n';
    message += '```\n';
    message += 'Main queue: ' + main.Attributes.ApproximateNumberOfMessages
    message += 'Other queue: ' + dl.Attributes.ApproximateNumberOfMessages 
    message += '```';
    if (err) return callback(err);
    return callback(null, message);
  });
}

function getInfo(url, callback) {
  var sqs = new AWS.SQS(); // retrieving queue information


  var params = {
    AttributeNames: ['All'],
    QueueUrl: url
  };

  sqs.getQueueAttributes(params, function(err, data) {
    if (err) return callback(err);
    return callback(null, data);
  });
}

Here is the test:

test('Check main + dl queue returns total message(s) in queue(s)', function(assert) {
  AWS.stub('SQS', 'getQueueAttributes', function(params, callback) {
    var response = {'Attributes':{'ApproximateNumberOfMessages':5, 'ApproximateNumberOfMessagesNotVisible':3}}
    callback(null, response);
  });		

  debugger; 

  index.retrieveQueueLengths(function(err, result) {
    assert.equal(err, null);
    assert.equal(result.length, 97);
    assert.equal(result[29], '5');

    AWS.SQS.restore()
    assert.end();
  })
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.