"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tape_1 = __importDefault(require("tape-promise/tape"));
const uuid_1 = require("uuid");
const cactus_core_api_1 = require("@hyperledger/cactus-core-api");
const public_api_1 = require("../../../main/typescript/public-api");
const metrics_1 = require("../../../main/typescript/prometheus-exporter/metrics");
const public_api_2 = require("../../../main/typescript/public-api");
const logLevel = "TRACE";
tape_1.default("can import plugins at runtime (CLI)", async (t) => {
    const configService = new public_api_1.ConfigService();
    const apiServerOptions = configService.newExampleConfig();
    apiServerOptions.authorizationProtocol = public_api_1.AuthorizationProtocol.NONE;
    apiServerOptions.configFile = "";
    apiServerOptions.apiCorsDomainCsv = "*";
    apiServerOptions.apiPort = 0;
    apiServerOptions.cockpitPort = 0;
    apiServerOptions.apiTlsEnabled = false;
    apiServerOptions.plugins = [
        {
            packageName: "@hyperledger/cactus-plugin-keychain-memory",
            type: cactus_core_api_1.PluginImportType.Local,
            options: {
                instanceId: uuid_1.v4(),
                keychainId: uuid_1.v4(),
                logLevel,
            },
        },
    ];
    const config = configService.newExampleConfigConvict(apiServerOptions);
    const apiServer = new public_api_1.ApiServer({
        config: config.getProperties(),
    });
    const startResponse = apiServer.start();
    await t.doesNotReject(startResponse, "started API server dynamic imports OK");
    t.ok(startResponse, "startResponse truthy OK");
    const addressInfoApi = (await startResponse).addressInfoApi;
    const protocol = apiServerOptions.apiTlsEnabled ? "https" : "http";
    const { address, port } = addressInfoApi;
    const apiHost = `${protocol}://${address}:${port}`;
    t.comment(`Metrics URL: ${apiHost}/api/v1/api-server/get-prometheus-exporter-metrics`);
    const apiConfig = new cactus_core_api_1.Configuration({ basePath: apiHost });
    const apiClient = new public_api_2.DefaultApi(apiConfig);
    {
        const res = await apiClient.getPrometheusExporterMetricsV1();
        const promMetricsOutput = "# HELP " +
            metrics_1.K_CACTUS_API_SERVER_TOTAL_PLUGIN_IMPORTS +
            " Total number of plugins imported\n" +
            "# TYPE " +
            metrics_1.K_CACTUS_API_SERVER_TOTAL_PLUGIN_IMPORTS +
            " gauge\n" +
            metrics_1.K_CACTUS_API_SERVER_TOTAL_PLUGIN_IMPORTS +
            '{type="' +
            metrics_1.K_CACTUS_API_SERVER_TOTAL_PLUGIN_IMPORTS +
            '"} 1';
        t.ok(res);
        t.ok(res.data);
        t.equal(res.status, 200);
        t.true(res.data.includes(promMetricsOutput), "Total 1 plugins imported as expected. RESULT OK");
    }
    tape_1.default.onFinish(() => apiServer.shutdown());
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnVudGltZS1wbHVnaW4taW1wb3J0cy50ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vc3JjL3Rlc3QvdHlwZXNjcmlwdC9pbnRlZ3JhdGlvbi9ydW50aW1lLXBsdWdpbi1pbXBvcnRzLnRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw2REFBK0M7QUFDL0MsK0JBQW9DO0FBSXBDLGtFQUErRTtBQUUvRSxvRUFJNkM7QUFFN0Msa0ZBQWdIO0FBRWhILG9FQUFpRjtBQUVqRixNQUFNLFFBQVEsR0FBaUIsT0FBTyxDQUFDO0FBRXZDLGNBQUksQ0FBQyxxQ0FBcUMsRUFBRSxLQUFLLEVBQUUsQ0FBTyxFQUFFLEVBQUU7SUFDNUQsTUFBTSxhQUFhLEdBQUcsSUFBSSwwQkFBYSxFQUFFLENBQUM7SUFDMUMsTUFBTSxnQkFBZ0IsR0FBRyxhQUFhLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQztJQUMxRCxnQkFBZ0IsQ0FBQyxxQkFBcUIsR0FBRyxrQ0FBcUIsQ0FBQyxJQUFJLENBQUM7SUFDcEUsZ0JBQWdCLENBQUMsVUFBVSxHQUFHLEVBQUUsQ0FBQztJQUNqQyxnQ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