logdna/test/test.ts

92 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-11-01 17:13:34 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2018-11-02 08:07:47 +00:00
import * as logdna from '../ts/index';
2018-11-01 17:13:34 +00:00
2018-11-02 08:07:47 +00:00
import { Qenv } from '@pushrocks/qenv';
2018-11-04 20:21:34 +00:00
import { ILogPackage } from '@pushrocks/smartlog-interfaces';
2018-11-01 17:13:34 +00:00
2018-11-02 08:07:47 +00:00
const testQenv = new Qenv('./', './.nogit');
let testLogDnaAccount: logdna.LogdnaAccount;
let testLogMessage: logdna.LogdnaMessage;
tap.test('should create a valid logDna account', async () => {
2020-06-03 03:13:01 +00:00
testLogDnaAccount = new logdna.LogdnaAccount(testQenv.getEnvVarOnDemand('LOGDNA_APIKEY'));
2018-11-02 08:07:47 +00:00
});
tap.test('should create a standard log message', async () => {
2018-11-02 12:57:14 +00:00
testLogMessage = logdna.LogdnaMessage.fromSmartLogPackage({
2018-11-04 17:44:28 +00:00
timestamp: Date.now(),
type: 'log',
2018-11-03 22:31:26 +00:00
level: 'info',
context: {
2018-11-02 12:57:14 +00:00
company: 'Lossless GmbH',
companyunit: 'lossless.cloud',
containerName: 'ci-mojoio-logdna',
environment: 'test',
runtime: 'node',
2018-11-04 14:37:55 +00:00
zone: 'shipzone'
2018-11-02 12:57:14 +00:00
},
2018-11-04 17:44:28 +00:00
message: 'this is an awesome log message sent by the tapbundle test'
2018-11-02 12:57:14 +00:00
});
2018-11-02 08:07:47 +00:00
});
2018-11-02 18:12:16 +00:00
tap.test('should send the message', async () => {
2018-11-05 22:52:39 +00:00
await testLogDnaAccount.sendLogdnaMessage(testLogMessage);
2018-11-03 15:22:32 +00:00
});
2018-11-02 18:12:16 +00:00
2018-11-04 20:21:34 +00:00
tap.test('should send in order', async () => {
let i = 1;
while (i < 21) {
const testSmartlogMessage: ILogPackage = {
timestamp: Date.now(),
type: 'log',
level: 'info',
context: {
company: 'Lossless GmbH',
companyunit: 'lossless.cloud',
containerName: 'ci-mojoio-logdna',
environment: 'test',
runtime: 'node',
zone: 'shipzone'
},
message: `this is an awesome log message sent by the tapbundle test #${i}`
};
testLogDnaAccount.sendSmartlogPackage(testSmartlogMessage);
i++;
}
2020-06-03 03:42:15 +00:00
2020-06-03 03:45:10 +00:00
const testSmartlogMessage2: ILogPackage = {
2020-06-03 03:42:15 +00:00
timestamp: Date.now(),
type: 'log',
level: 'warn',
context: {
company: 'Lossless GmbH',
companyunit: 'lossless.cloud',
containerName: 'ci-mojoio-logdna',
environment: 'test',
runtime: 'node',
zone: 'shipzone'
},
message: `this is an awesome log message sent by the tapbundle test #${i}`
};
2020-06-03 03:45:10 +00:00
testLogDnaAccount.sendSmartlogPackage(testSmartlogMessage2);
const testSmartlogMessage3: ILogPackage = {
timestamp: Date.now(),
type: 'log',
level: 'error',
context: {
company: 'Lossless GmbH',
companyunit: 'lossless.cloud',
containerName: 'ci-mojoio-logdna',
environment: 'test',
runtime: 'node',
zone: 'shipzone'
},
message: `this is an awesome log message sent by the tapbundle test #${i}`
};
testLogDnaAccount.sendSmartlogPackage(testSmartlogMessage3);
2020-06-03 03:13:01 +00:00
});
2018-11-04 20:21:34 +00:00
2018-11-02 08:07:47 +00:00
tap.start();