1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
"use strict";
const { BaseAction } = ChromeUtils.importESModule(
"resource://normandy/actions/BaseAction.sys.mjs"
);
const { ConsoleLogAction } = ChromeUtils.importESModule(
"resource://normandy/actions/ConsoleLogAction.sys.mjs"
);
const { Uptake } = ChromeUtils.importESModule(
"resource://normandy/lib/Uptake.sys.mjs"
);
// Test that logging works
add_task(async function logging_works() {
const action = new ConsoleLogAction();
const infoStub = sinon.stub(action.log, "info");
try {
const recipe = { id: 1, arguments: { message: "Hello, world!" } };
await action.processRecipe(recipe, BaseAction.suitability.FILTER_MATCH);
is(action.lastError, null, "lastError should be null");
Assert.deepEqual(
infoStub.args,
["Hello, world!"],
"the message should be logged"
);
} finally {
infoStub.restore();
}
});
// test that argument validation works
decorate_task(
withStub(Uptake, "reportRecipe"),
async function arguments_are_validated({ reportRecipeStub }) {
const action = new ConsoleLogAction();
const infoStub = sinon.stub(action.log, "info");
try {
// message is required
let recipe = { id: 1, arguments: {} };
await action.processRecipe(recipe, BaseAction.suitability.FILTER_MATCH);
is(action.lastError, null, "lastError should be null");
Assert.deepEqual(infoStub.args, [], "no message should be logged");
Assert.deepEqual(reportRecipeStub.args, [
[recipe, Uptake.RECIPE_EXECUTION_ERROR],
]);
reportRecipeStub.reset();
// message must be a string
recipe = { id: 1, arguments: { message: 1 } };
await action.processRecipe(recipe, BaseAction.suitability.FILTER_MATCH);
is(action.lastError, null, "lastError should be null");
Assert.deepEqual(infoStub.args, [], "no message should be logged");
Assert.deepEqual(reportRecipeStub.args, [
[recipe, Uptake.RECIPE_EXECUTION_ERROR],
]);
} finally {
infoStub.restore();
}
}
);
|