Skip to content

Add Expected Failures #88

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ module.exports = function (grunt) {
handler: 'myfunction'
}
},
expected_failure_options: {
options: {
file_name: 'test/fixtures/failing_index.js',
event: 'test/fixtures/event.json',
handler: 'myfunction',
expect_fail: true
}
},
unexpected_success_options: {
options: {
file_name: 'test/fixtures/index.js',
event: 'test/fixtures/event.json',
expect_fail: true
}
},
package_folder_options: {
options: {
package_folder: 'test/fixtures/package_folder_option',
Expand Down
4 changes: 2 additions & 2 deletions test/expected/custom_options
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ value1 = value4
value2 = value5
value3 = value6

Success! Message:
------------------
Expected Success! Message:
-----------------------------
Hello World

Done, without errors.
4 changes: 2 additions & 2 deletions test/expected/default_options
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ value1 = value1
value2 = value2
value3 = value3

Success! Message:
------------------
Expected Success! Message:
-----------------------------
Hello World

Done, without errors.
11 changes: 11 additions & 0 deletions test/expected/expected_failure_options
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Running "lambda_invoke:expected_failure_options" (lambda_invoke) task

value1 = value1
value2 = value2
value3 = value3

Expected Failure! Message:
-----------------------------
Hello World

Done, without errors.
4 changes: 2 additions & 2 deletions test/expected/failure_options
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ value1 = value1
value2 = value2
value3 = value3

Failure! Message:
------------------
Unexpected Failure! Message:
-----------------------------
Hello World
Warning: Task "lambda_invoke:failure_options" failed. Use --force to continue.

Expand Down
12 changes: 12 additions & 0 deletions test/expected/unexpected_success_options
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Running "lambda_invoke:unexpected_success_options" (lambda_invoke) task

value1 = value1
value2 = value2
value3 = value3

Unexpected Success! Message:
-----------------------------
Hello World
Warning: Task "lambda_invoke:unexpected_success_options" failed. Use --force to continue.

Aborted due to warnings.
32 changes: 30 additions & 2 deletions test/integ/lambda_invoke_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,34 @@ exports.lambda_invoke = {
test.done();
});
},
expected_failure_options: function (test) {
test.expect(1);

grunt.util.spawn({
grunt: true,
args: ['lambda_invoke:expected_failure_options', '--no-color']
}, function (err, result, code) {

var expected = getNormalizedFile('test/expected/expected_failure_options');
var actual = grunt.util.normalizelf(result.stdout);
test.equal(actual, expected);
test.done();
});
},
unexpected_success_options: function (test) {
test.expect(1);

grunt.util.spawn({
grunt: true,
args: ['lambda_invoke:unexpected_success_options', '--no-color']
}, function (err, result, code) {

var expected = getNormalizedFile('test/expected/unexpected_success_options');
var actual = grunt.util.normalizelf(result.stdout);
test.equal(actual, expected);
test.done();
});
},
package_folder_options: function (test) {
test.expect(2);

Expand All @@ -85,9 +113,9 @@ exports.lambda_invoke = {
var cwd = process.cwd();

// test cwd inside the function
var expected_cwd = 'Running "lambda_invoke:package_folder_options" (lambda_invoke) task\n\n\nSuccess! Message:\n------------------\n' +
var expected_cwd = grunt.util.normalizelf('Running "lambda_invoke:package_folder_options" (lambda_invoke) task\n\n\nExpected Success! Message:\n-----------------------------\n' +
path.join(cwd, 'test/fixtures/package_folder_option') +
'\n\nDone, without errors.';
'\n\nDone, without errors.');

var actual_cwd = grunt.util.normalizelf(result.stdout);
test.equal(actual_cwd, expected_cwd);
Expand Down
91 changes: 67 additions & 24 deletions test/unit/invoke_task_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ invokeTaskTests.testLambdaEnvironment = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -110,7 +110,7 @@ invokeTaskTests.testDoneSucceed = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -132,8 +132,8 @@ invokeTaskTests.testDoneWithObjectStatus = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[4], '{"some":"object"}');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], '{\n "some": "object"\n}');
test.done();
}
};
Expand All @@ -155,7 +155,7 @@ invokeTaskTests.testDoneUndefined = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -178,8 +178,8 @@ invokeTaskTests.testDoneError = function(test) {
callback: function(harness) {
test.equal(harness.status, false);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Failure! Message:');
test.equal(harness.output[4], '{"message":"Some Error"}');
test.equal(harness.output[2], 'Unexpected Failure! Message:');
test.equal(harness.output[4], '{\n "message": "Some Error"\n}');
test.done();
}
};
Expand All @@ -201,8 +201,8 @@ invokeTaskTests.testFail = function(test) {
callback: function(harness) {
test.equal(harness.status, false);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Failure! Message:');
test.equal(harness.output[4], '{"message":"Some Error"}');
test.equal(harness.output[2], 'Unexpected Failure! Message:');
test.equal(harness.output[4], '{\n "message": "Some Error"\n}');
test.done();
}
};
Expand All @@ -225,7 +225,7 @@ invokeTaskTests.testFileName = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -249,7 +249,7 @@ invokeTaskTests.testHandler = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -273,7 +273,7 @@ invokeTaskTests.testFileName = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand Down Expand Up @@ -302,7 +302,7 @@ invokeTaskTests.testEvent = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand Down Expand Up @@ -331,7 +331,7 @@ invokeTaskTests.testClientContext = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand Down Expand Up @@ -360,7 +360,7 @@ invokeTaskTests.testIdentity = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand Down Expand Up @@ -389,7 +389,7 @@ invokeTaskTests.testPackageFolder = function(test) {
test.equal(process.cwd(), original);
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -414,7 +414,7 @@ invokeTaskTests.testNoClientContext = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -439,7 +439,7 @@ invokeTaskTests.testNoIdentity = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -460,7 +460,7 @@ invokeTaskTests.testCallbackSucceed = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -482,8 +482,8 @@ invokeTaskTests.testCallbackWithObjectStatus = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[4], '{"some":"object"}');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], '{\n "some": "object"\n}');
test.done();
}
};
Expand All @@ -505,7 +505,7 @@ invokeTaskTests.testCallbackUndefined = function(test) {
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Success! Message:');
test.equal(harness.output[2], 'Expected Success! Message:');
test.equal(harness.output[4], 'My Message');
test.done();
}
Expand All @@ -528,13 +528,56 @@ invokeTaskTests.testCallbackError = function(test) {
callback: function(harness) {
test.equal(harness.status, false);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Failure! Message:');
test.equal(harness.output[4], '{"message":"Some Error"}');
test.equal(harness.output[2], 'Unexpected Failure! Message:');
test.equal(harness.output[4], '{\n "message": "Some Error"\n}');
test.done();
}
};
gruntMock.execute(invokeTask.getHandler, harnessParams);
};

invokeTaskTests.testUnexpectedSuccess = function(test) {
test.expect(4);

setLambdaFunction(function(event, context, callback) {
callback(null, 'My message');
});

var invokeTask = require('../../utils/invoke_task');

var harnessParams = {
options: {expect_fail: true},
callback: function(harness) {
test.equal(harness.status, false);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Unexpected Success! Message:');
test.equal(harness.output[4], 'My message');
test.done();
}
};
gruntMock.execute(invokeTask.getHandler, harnessParams);
};

invokeTaskTests.testExpectedFailure = function(test) {
test.expect(4);

setLambdaFunction(function(event, context, callback) {
callback({message: 'Some Error'}, 'My message');
});

var invokeTask = require('../../utils/invoke_task');

var harnessParams = {
options: {expect_fail: true},
callback: function(harness) {
test.equal(harness.status, true);
test.equal(harness.output.length, 5);
test.equal(harness.output[2], 'Expected Failure! Message:');
test.equal(harness.output[4], '{\n "message": "Some Error"\n}');
test.done();
}
};
gruntMock.execute(invokeTask.getHandler, harnessParams);
};

module.exports = invokeTaskTests;
Loading