"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.adlsTestHelper = void 0;
const internal_1 = require("../internal");
const Storage_1 = require("../Storage");
exports.adlsTestHelper = {
    createAdapterWithSharedKey(rootRelativePath, testBlobHostname = false, httpsHostname = false) {
        let hostname = httpsHostname ? process.env['ADLS_HTTPS_HOSTNAME'] : process.env['ADLS_HOSTNAME'];
        const rootPath = process.env['ADLS_ROOTPATH'];
        const sharedKey = process.env['ADLS_SHAREDKEY'];
        expect(internal_1.StringUtils.isNullOrWhiteSpace(hostname))
            .toBe(false);
        expect(internal_1.StringUtils.isNullOrWhiteSpace(rootPath))
            .toBe(false);
        expect(internal_1.StringUtils.isNullOrWhiteSpace(sharedKey))
            .toBe(false);
        if (testBlobHostname) {
            hostname = hostname.replace('dfs', 'blob');
        }
        return new Storage_1.ADLSAdapter(hostname, exports.adlsTestHelper.getFullRootPath(rootPath, rootRelativePath), sharedKey);
    },
    createAdapterWithClientId(rootRelativePath, specifyEndpoint = false, testBlobHostname = false) {
        let hostname = process.env['ADLS_HOSTNAME'];
        const rootPath = process.env['ADLS_ROOTPATH'];
        const tenant = process.env['ADLS_TENANT'];
        const clientId = process.env['ADLS_CLIENTID'];
        const clientSecret = process.env['ADLS_CLIENTSECRET'];
        expect(internal_1.StringUtils.isNullOrWhiteSpace(hostname))
            .toBe(false);
        expect(internal_1.StringUtils.isNullOrWhiteSpace(rootPath))
            .toBe(false);
        expect(internal_1.StringUtils.isNullOrWhiteSpace(tenant))
            .toBe(false);
        expect(internal_1.StringUtils.isNullOrWhiteSpace(clientId))
            .toBe(false);
        expect(internal_1.StringUtils.isNullOrWhiteSpace(clientSecret))
            .toBe(false);
        if (testBlobHostname) {
            hostname = hostname.replace('dfs', 'blob');
        }
        if (specifyEndpoint) {
            return new Storage_1.ADLSAdapter(hostname, exports.adlsTestHelper.getFullRootPath(rootPath, rootRelativePath), tenant, clientId, clientSecret, internal_1.azureCloudEndpoint.AzurePublic);
        }
        return new Storage_1.ADLSAdapter(hostname, exports.adlsTestHelper.getFullRootPath(rootPath, rootRelativePath), tenant, clientId, clientSecret);
    },
    getFullRootPath(first, second) {
        if (second === undefined || second === null) {
            return first;
        }
        if (first.endsWith('/')) {
            first = first.substring(0, first.length - 1);
        }
        if (second.startsWith('/')) {
            second = second.substring(1);
        }
        return `${first}/${second}`;
    }
};
//# sourceMappingURL=adlsTestHelper.js.map