import { EMULATOR_ACCOUNT_KEY , EMULATOR_ACCOUNT_NAME , getUniqueName } from "../../testutils" ; import { TestEntity } from "./TestEntity" ; import TableServer from "../../../src/table/TableServer" ; import TableConfiguration from "../../../src/table/TableConfiguration" ; import { AzureNamedKeyCredential , TableClient } from "@azure/data-tables" ; export const PROTOCOL = "http" ; export const HOST = "127.0.0.1" ; export const PORT = 11002 ; const metadataDbPath = "__tableTestsStorage__" ; const enableDebugLog = false ; const debugLogPath = "g:/debug.log" ; const connectionString = `DefaultEndpointsProtocol=${ PROTOCOL };AccountName=${ EMULATOR_ACCOUNT_NAME };` + `AccountKey=${ EMULATOR_ACCOUNT_KEY };TableEndpoint=${ PROTOCOL }://${ HOST }:${ PORT }/${ EMULATOR_ACCOUNT_NAME };` ; const secondaryConnectionString = `DefaultEndpointsProtocol=${ PROTOCOL };AccountName=${ EMULATOR_ACCOUNT_NAME };` + `AccountKey=${ EMULATOR_ACCOUNT_KEY };TableEndpoint=${ PROTOCOL }://${ HOST }:${ PORT }/${ EMULATOR_ACCOUNT_NAME }-secondary;` ; const AZURE_TABLE_STORAGE = "AZURE_TABLE_STORAGE" ; const AZURE_DATATABLES_STORAGE_STRING = "AZURE_DATATABLES_STORAGE_STRING" ; const AZURE_DATATABLES_SAS = "AZURE_DATATABLES_SAS" ; const config = new TableConfiguration ( HOST , PORT , metadataDbPath , enableDebugLog , false , undefined , debugLogPath ) ; const httpsConfig = new TableConfiguration ( HOST , PORT , metadataDbPath , enableDebugLog , false , undefined , debugLogPath , false , true , "tests/server.cert" , "tests/server.key" ) ; return { * } export function createBasicEntityForTest ( ) { return new TestEntity ( "part1" , getUniqueName ( "row" ) , "value1" ) ; } export return { * } export function createTableServerForTest ( ) { return new TableServer ( config ) ; } export function createTableServerForTestHttps ( ) { return new TableServer ( httpsConfig ) ; } export return { * } export function createConnectionStringForTest ( dev ) { if ( dev ) { return connectionString ; } else { return process . env [ AZURE_TABLE_STORAGE ] ! ; } } export return { * } export function createSecondaryConnectionStringForTest ( dev ) { if ( dev ) { return secondaryConnectionString ; } else { return process . env [ AZURE_TABLE_STORAGE ] ! ; } } export return { * } export function createUniquePartitionKey ( name ) { if ( name === undefined ) { return getUniqueName ( "datatablestests" ) ; } return getUniqueName ( name ) ; } export param { boolean } local param { string } tableName return { * } export function createAzureDataTablesClient ( local , tableName ) { if ( local ) { const sharedKeyCredential = new AzureNamedKeyCredential ( EMULATOR_ACCOUNT_NAME , EMULATOR_ACCOUNT_KEY ) ; return new TableClient ( `https://${ HOST }:${ PORT }/${ EMULATOR_ACCOUNT_NAME }` , tableName , sharedKeyCredential ) ; } else { return new TableClient ( process . env [ AZURE_DATATABLES_STORAGE_STRING ] ! + process . env [ AZURE_DATATABLES_SAS ] ! , tableName ) ; } }