"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const TestServer_1 = require("../TestServer");
const Logger_1 = require("../shared/Logger");
const chai_1 = require("chai");
const chai = require("chai");
chai.use(require("chai-as-promised"));
const tmp = require("tmp");
const path = require("path");
const fs = require("fs-extra");
class Expecter extends Logger_1.Logger {
    constructor(expectLines) {
        super();
        this.expected = expectLines.slice();
    }
    log(level, msg, ctx) {
        while (msg.indexOf(this.expected[0]) >= 0) {
            this.expected.shift();
        }
    }
    fulfilled() {
        return this.expected.length === 0;
    }
}
describe('Backup command', function () {
    let server;
    let oldros;
    let newros;
    beforeEach(() => __awaiter(this, void 0, void 0, function* () {
        oldros = tmp.dirSync({ unsafeCleanup: true });
        fs.mkdirSync(path.join(oldros.name, "sync"));
        newros = tmp.dirSync({ unsafeCleanup: true });
        server = new TestServer_1.TestServer();
    }));
    afterEach(() => __awaiter(this, void 0, void 0, function* () {
        oldros.removeCallback();
        newros.removeCallback();
    }));
    it('should succeed', () => __awaiter(this, void 0, void 0, function* () {
        const expecter = new Expecter([
            `The data directory ${oldros.name} was backed up in the directory ${newros.name}`,
        ]);
        yield chai_1.assert.isFulfilled(server["runBackup"]({
            from: oldros.name,
            to: newros.name,
            overwrite: false,
        }, expecter));
        chai_1.assert.isTrue(expecter.fulfilled());
    }));
});
//# sourceMappingURL=backup.spec.js.map