Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Hubs] Disable CI logging #31855

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/eventhub/event-hubs/test/utils/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Licensed under the MIT License.

import { afterAll, beforeAll, inject } from "vitest";
import type { AzureLogLevel } from "@azure/logger";
import { setLogLevel } from "@azure/logger";
import { EnvVarKeys } from "./constants.js";

const logLevel = inject("AZURE_LOG_LEVEL") as AzureLogLevel;
const logLevel = inject(EnvVarKeys.AZURE_LOG_LEVEL);
const localStorage: { debug?: string } = {};

beforeAll(async function () {
Expand Down
25 changes: 18 additions & 7 deletions sdk/eventhub/event-hubs/test/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@ import { resolve as resolvePath } from "path";
import type { GlobalSetupContext } from "vitest/node";
import { EnvVarKeys } from "./constants.js";
import * as MOCKS from "./constants.js";
import type { AzureLogLevel } from "@azure/logger";

declare module "vitest" {
type MyEnvVarKeys = {
[K in keyof typeof EnvVarKeys]: string;
};
[K in keyof Omit<typeof EnvVarKeys, "AZURE_LOG_LEVEL">]: string;
} & { AZURE_LOG_LEVEL: AzureLogLevel | undefined };
export interface ProvidedContext extends MyEnvVarKeys {}
}

const defaultLogLevel = "error";

function assertEnvironmentVariable(key: string): string {
function assertEnvironmentVariable<K extends EnvVarKeys.AZURE_LOG_LEVEL>(
key: K,
): AzureLogLevel | undefined;
function assertEnvironmentVariable(key: string): string;
function assertEnvironmentVariable(key: string): string | undefined {
const value = process.env[key];
// handle defaults
if (!value) {
switch (key) {
case EnvVarKeys.TEST_MODE:
return "mock";
case EnvVarKeys.AZURE_LOG_LEVEL:
return defaultLogLevel;
return undefined;
default:
throw new Error(`Environment variable ${key} is not defined.`);
}
Expand All @@ -51,6 +54,14 @@ function createMockServer(options: MockServerOptions = {}): MockEventHub {
});
}

function getAzureLogLevel(): AzureLogLevel | undefined {
const val = process.env[EnvVarKeys.AZURE_LOG_LEVEL];
if (![undefined, "error", "warning", "info", "verbose"].includes(val)) {
throw new Error(`Invalid value for ${EnvVarKeys.AZURE_LOG_LEVEL}: ${val}`);
}
return val as AzureLogLevel | undefined;
}

export default async function ({ provide }: GlobalSetupContext) {
if (process.env[EnvVarKeys.TEST_MODE]?.toLowerCase() === "live") {
const kvUri = assertEnvironmentVariable("KEYVAULT_URI");
Expand All @@ -76,7 +87,7 @@ export default async function ({ provide }: GlobalSetupContext) {
provide(EnvVarKeys.EVENTHUB_NAME, MOCKS.EVENTHUB_NAME);
provide(EnvVarKeys.EVENTHUB_CONSUMER_GROUP_NAME, MOCKS.EVENTHUB_CONSUMER_GROUP_NAME);
provide(EnvVarKeys.EVENTHUB_FQDN, MOCKS.EVENTHUB_FQDN);
provide(EnvVarKeys.AZURE_LOG_LEVEL, process.env[EnvVarKeys.AZURE_LOG_LEVEL] || defaultLogLevel);
provide(EnvVarKeys.AZURE_LOG_LEVEL, getAzureLogLevel());
provide(EnvVarKeys.EVENTHUB_CONNECTION_STRING, MOCKS.EVENTHUB_CONNECTION_STRING_WITH_KEY);
const server = createMockServer();
await server.start();
Expand Down
Loading