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] Update Identity tests to use public clients #9343

Merged
merged 2 commits into from
Jun 8, 2020
Merged
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
48 changes: 32 additions & 16 deletions sdk/eventhub/event-hubs/test/node/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import chaiAsPromised from "chai-as-promised";
chai.use(chaiAsPromised);
import chaiString from "chai-string";
chai.use(chaiString);
import { EventHubClient } from "../../src/impl/eventHubClient";
import { EnvVarKeys, getEnvVars } from "../utils/testUtils";
import { EnvironmentCredential } from "@azure/identity";
import { EnvironmentCredential, TokenCredential } from "@azure/identity";
import { EventHubProducerClient, EventHubConsumerClient } from "../../src";
const env = getEnvVars();

describe("Create EventHubClient using Azure Identity", function(): void {
it("creates an EventHubClient from an Azure.Identity credential", async function(): Promise<
void
> {
describe("Create clients using Azure Identity", function(): void {
let endpoint: string;
let credential: TokenCredential;
before("validate environment", function() {
should.exist(
env[EnvVarKeys.AZURE_CLIENT_ID],
"define AZURE_CLIENT_ID in your environment before running integration tests."
Expand All @@ -32,23 +32,39 @@ describe("Create EventHubClient using Azure Identity", function(): void {
env[EnvVarKeys.EVENTHUB_CONNECTION_STRING],
"define EVENTHUB_CONNECTION_STRING in your environment before running integration tests."
);

// This is of the form <your-namespace>.servicebus.windows.net
const endpoint = (env.EVENTHUB_CONNECTION_STRING.match("Endpoint=sb://(.*)/;") || "")[1];
endpoint = (env.EVENTHUB_CONNECTION_STRING.match("Endpoint=sb://(.*)/;") || "")[1];
credential = new EnvironmentCredential();
});

const credential = new EnvironmentCredential();
const client = new EventHubClient(endpoint, env.EVENTHUB_NAME, credential);
it("creates an EventHubProducerClient from an Azure.Identity credential", async function(): Promise<
void
> {
const client = new EventHubProducerClient(endpoint, env.EVENTHUB_NAME, credential);
should.equal(client.fullyQualifiedNamespace, endpoint);

// Extra check involving actual call to the service to ensure this works
const hubInfo = await client.getProperties();
const hubInfo = await client.getEventHubProperties();
should.equal(hubInfo.name, client.eventHubName);

await client.close();
});

it("Verify fullyQualifiedNamespace when creating an EventHubClient from an Azure.Identity credential", function(): void {
const endpoint = "test.servicebus.windows.net";
const credential = new EnvironmentCredential();
const client = new EventHubClient(endpoint, "my-event-hub-name", credential);
should.equal(client.fullyQualifiedNamespace, "test.servicebus.windows.net");
it("creates an EventHubConsumerClient from an Azure.Identity credential", async function(): Promise<
void
> {
const client = new EventHubConsumerClient(
EventHubConsumerClient.defaultConsumerGroupName,
endpoint,
env.EVENTHUB_NAME,
credential
);
should.equal(client.fullyQualifiedNamespace, endpoint);

// Extra check involving actual call to the service to ensure this works
const hubInfo = await client.getEventHubProperties();
should.equal(hubInfo.name, client.eventHubName);

await client.close();
});
});