@webda/aws
Version:
Webda AWS Services implementation
104 lines • 4.42 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { CloudWatchLogs } from "@aws-sdk/client-cloudwatch-logs";
import { suite, test } from "@testdeck/mocha";
import * as assert from "assert";
import { checkLocalStack, defaultCreds, WebdaAwsTest } from "../index.spec.js";
let CloudWatchLoggerTest = class CloudWatchLoggerTest extends WebdaAwsTest {
getTestConfiguration() {
return process.cwd() + "/test/config-cloudwatch.json";
}
async before() {
await checkLocalStack();
let cloudwatch = new CloudWatchLogs({
credentials: defaultCreds,
endpoint: "http://localhost:4566",
region: "us-east-1"
});
try {
await cloudwatch.deleteLogGroup({
logGroupName: "webda-test"
});
}
catch (err) {
// Skip bad delete
}
await super.before();
this.service = this.getService("CloudWatchLogger");
assert.notStrictEqual(this.service, undefined);
}
async basic() {
this.webda.log("INFO", "Plop 0", "Test");
this.webda.log("DEBUG", "Plop 1", "Test");
this.webda.log("DEBUG", "Plop 2", "Test");
this.webda.log("DEBUG", "Plop 3", "Test");
this.webda.getLogger("whatever").logProgressStart("test", 100, "other");
this.webda.log("DEBUG", "Plop 4", "Test");
await this.webda.emitSync("Webda.Result");
let res = await this.service._cloudwatch.describeLogStreams({
logGroupName: "webda-test"
});
assert.strictEqual(res.logStreams.length, 1);
assert.notStrictEqual(res.logStreams[0].lastEventTimestamp, undefined);
this.service.getParameters().logGroupName = undefined;
await assert.rejects(() => this.service.init(), /Require a log group `logGroupName` parameter/);
}
aws() {
assert.deepStrictEqual(this.service.getARNPolicy("plop"), {
Action: ["logs:*"],
Effect: "Allow",
Resource: [
"arn:aws:logs:us-east-1:plop:log-group:webda-test",
"arn:aws:logs:us-east-1:plop:log-group:webda-test:*:*"
],
Sid: "CloudWatchLoggerCloudWatchLogger"
});
assert.deepStrictEqual(this.service.getCloudFormation(), {
CloudWatchLoggerLogGroup: {
Properties: {
LogGroupName: "webda-test"
},
Type: "AWS::Logs::LogGroup"
}
});
this.service.getParameters().CloudFormationSkip = true;
assert.deepStrictEqual(this.service.getCloudFormation(), {});
}
async secondRun() {
// Update config to use the stepper
this.service.getParameters().singlePush = true;
this.webda.log("INFO", "Plop 0", "Test");
this.webda.log("DEBUG", "Plop 1", "Test");
await this.sleep(1000);
let res = await this.service._cloudwatch.describeLogStreams({
logGroupName: "webda-test"
});
assert.strictEqual(res.logStreams.length, 1);
assert.notStrictEqual(res.logStreams[0].lastEventTimestamp, undefined);
this.webda.log("DEBUG", "Plop 2", "Test");
this.webda.log("DEBUG", "Plop 3", "Test");
this.webda.log("DEBUG", "Plop 4", "Test");
await this.webda.emitSync("Webda.Result");
res = await this.service._cloudwatch.describeLogStreams({
logGroupName: "webda-test"
});
assert.strictEqual(res.logStreams.length, 1);
}
};
__decorate([
test
], CloudWatchLoggerTest.prototype, "basic", null);
__decorate([
test
], CloudWatchLoggerTest.prototype, "aws", null);
__decorate([
test
], CloudWatchLoggerTest.prototype, "secondRun", null);
CloudWatchLoggerTest = __decorate([
suite
], CloudWatchLoggerTest);
//# sourceMappingURL=cloudwatchlogger.spec.js.map