Tidy logging in integration tests

This commit is contained in:
gnuxie 2021-09-30 15:32:20 +01:00
parent 400af48e6e
commit 776c1fe063
5 changed files with 10 additions and 9 deletions

View File

@ -293,6 +293,7 @@ export class Mjolnir {
* Stop Mjolnir from syncing and processing commands.
*/
public stop() {
LogService.info("Mjolnir", "Stopping Mjolnir...");
this.client.stop();
}

View File

@ -1,6 +1,6 @@
import axios from "axios";
import { HmacSHA1 } from "crypto-js";
import { MatrixClient, MemoryStorageProvider, PantalaimonClient } from "matrix-bot-sdk";
import { LogService, MatrixClient, MemoryStorageProvider, PantalaimonClient } from "matrix-bot-sdk";
import config from "../../src/config";
/**
@ -40,8 +40,7 @@ export async function registerNewTestUser(isAdmin: boolean) {
username = `mjolnir-test-user-${Math.floor(Math.random() * 100000)}`
await registerUser(username, username, username, isAdmin).then(_ => isUserValid = true).catch(e => {
if (e.isAxiosError && e?.response?.data?.errcode === 'M_USER_IN_USE') {
// FIXME: Replace with the real logging service.
console.log(`${username} already registered, trying another`);
LogService.debug("test/clientHelper", `${username} already registered, trying another`);
false // continue and try again
} else {
console.error(`failed to register user ${e}`);

View File

@ -16,7 +16,6 @@ export const mochaHooks = {
],
afterEach: [
async function() {
console.log("stopping mjolnir");
await this.mjolnir.stop();
// Mjolnir resolves config.managementRoom and overwrites it, so we undo this here
// after stopping Mjolnir for the next time we setup a Mjolnir and a management room.

View File

@ -1,5 +1,3 @@
import { doesNotMatch } from "assert";
import { assert } from "console";
import config from "../../src/config";
import { newTestUser, noticeListener } from "./clientHelper"
@ -17,7 +15,6 @@ describe("help command", () => {
// listener for getting the event reply
let reply = new Promise((resolve, reject) => {
client.on('room.message', noticeListener(config.managementRoom, (event) => {
console.log(event.event_id)
if (event.content.body.includes("Print status information")) {
resolve(event);
}

View File

@ -16,7 +16,10 @@ limitations under the License.
import {
MatrixClient,
PantalaimonClient,
MemoryStorageProvider
MemoryStorageProvider,
LogService,
LogLevel,
RichConsoleLogger
} from "matrix-bot-sdk";
import { Mjolnir} from '../../src/Mjolnir';
import config from "../../src/config";
@ -57,7 +60,9 @@ async function configureMjolnir() {
export async function makeMjolnir() {
await configureMjolnir();
console.info('starting mjolnir');
LogService.setLogger(new RichConsoleLogger());
LogService.setLevel(LogLevel.fromString(config.logLevel, LogLevel.DEBUG));
LogService.info("test/mjolnirSetupUtils", "Starting bot...");
const pantalaimon = new PantalaimonClient(config.homeserverUrl, new MemoryStorageProvider());
const client = await pantalaimon.createClientWithCredentials(config.pantalaimon.username, config.pantalaimon.password);
await ensureAliasedRoomExists(client, config.managementRoom);