"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 path_1 = __importDefault(require("path"));
const logLevel = "TRACE";
tape_1.default("can install plugin-ledger-connector-fabric", async (t) => {
    const pluginsPath = path_1.default.join(__dirname, // start at the current file's path
    "../../../../../../../", // walk back up to the project root
    ".tmp/test/cmd-api-server/runtime-plugin-imports_test", // the dir path from the root
    uuid_1.v4());
    const pluginManagerOptionsJson = JSON.stringify({
        pluginsPath,
        npmInstallMode: "noCache",
    });
    const configService = new public_api_1.ConfigService();
    const apiServerOptions = configService.newExampleConfig();
    apiServerOptions.authorizationProtocol = public_api_1.AuthorizationProtocol.NONE;
    apiServerOptions.pluginManagerOptionsJson = pluginManagerOptionsJson;
    apiServerOptions.configFile = "";
    apiServerOptions.apiCorsDomainCsv = "*";
    apiServerOptions.apiPort = 0;
    apiServerOptions.cockpitPort = 0;
    apiServerOptions.apiTlsEnabled = false;
    apiServerOptions.plugins = [
        {
            packageName: "@hyperledger/cactus-plugin-ledger-connector-fabric",
            type: cactus_core_api_1.PluginImportType.Local,
            options: {
                instanceId: uuid_1.v4(),
                logLevel,
                connectionProfile: {},
                peerBinary: "peer",
            },
        },
    ];
    const config = configService.newExampleConfigConvict(apiServerOptions);
    const apiServer = new public_api_1.ApiServer({
        config: config.getProperties(),
    });
    tape_1.default.onFinish(() => apiServer.shutdown());
    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.getPrometheusMetricsV1();
        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");
    }
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdGFsbC1iYXNpYy1wbHVnaW4tbGVkZ2VyLWNvbm5lY3Rvci1mYWJyaWMtMC03LTAudGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy90ZXN0L3R5cGVzY3JpcHQvdW5pdC9wbHVnaW5zL2luc3RhbGwtYmFzaWMtcGx1Z2luLWxlZGdlci1jb25uZWN0b3ItZmFicmljLTAtNy0wLnRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw2REFBK0M7QUFDL0MsK0JBQW9DO0FBSXBDLGtFQUErRTtBQUUvRSx1RUFJZ0Q7QUFFaEQscUZBQW1IO0FBRW5ILHVFQUFvRjtBQUNwRixnREFBd0I7QUFFeEIsTUFBTSxRQUFRLEdBQWlCLE9BQU8sQ0FBQztBQUV2QyxjQUFJ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