Skip to content

Commit

Permalink
Impleent spec test
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed Apr 18, 2024
1 parent 87c5595 commit 27f832a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 13 additions & 11 deletions test/tools/unified-spec-runner/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,63 +561,65 @@ function compareEvents(
);
}
}
return;
} else if (expectedEvent.serverHeartbeatStartedEvent) {
expect(actualEvent).to.be.instanceOf(ServerHeartbeatStartedEvent);
const expectedSdamEvent = expectedEvent.serverHeartbeatStartedEvent;
for (const property of Object.keys(expectedSdamEvent)) {
expect(actualEvent[property]).to.equal(expectedSdamEvent[property]);
}
return;
} else if (expectedEvent.serverHeartbeatFailedEvent) {
expect(actualEvent).to.be.instanceOf(ServerHeartbeatFailedEvent);
const expectedSdamEvent = expectedEvent.serverHeartbeatFailedEvent;
for (const property of Object.keys(expectedSdamEvent)) {
expect(actualEvent[property]).to.equal(expectedSdamEvent[property]);
}
return;
} else if (expectedEvent.serverHeartbeatSucceededEvent) {
expect(actualEvent).to.be.instanceOf(ServerHeartbeatSucceededEvent);
const expectedSdamEvent = expectedEvent.serverHeartbeatSucceededEvent;
for (const property of Object.keys(expectedSdamEvent)) {
expect(actualEvent[property]).to.equal(expectedSdamEvent[property]);
}
return;
} else if (expectedEvent.serverOpeningEvent) {
expect(actualEvent).to.be.instanceOf(ServerOpeningEvent);
const expectedSdamEvent = expectedEvent.serverOpeningEvent;
for (const property of Object.keys(expectedSdamEvent)) {
expect(actualEvent[property]).to.equal(expectedSdamEvent[property]);
}
return;
} else if (expectedEvent.serverClosedEvent) {
expect(actualEvent).to.be.instanceOf(ServerClosedEvent);
const expectedSdamEvent = expectedEvent.serverClosedEvent;
for (const property of Object.keys(expectedSdamEvent)) {
expect(actualEvent[property]).to.equal(expectedSdamEvent[property]);
}
return;
} else if (expectedEvent.topologyOpeningEvent) {
expect(actualEvent).to.be.instanceOf(TopologyOpeningEvent);
const expectedSdamEvent = expectedEvent.topologyOpeningEvent;
for (const property of Object.keys(expectedSdamEvent)) {
expect(actualEvent[property]).to.equal(expectedSdamEvent[property]);
}
return;
} else if (expectedEvent.topologyClosingEvent) {
expect(actualEvent).to.be.instanceOf(TopologyClosedEvent);
const expectedSdamEvent = expectedEvent.topologyClosingEvent;
for (const property of Object.keys(expectedSdamEvent)) {
expect(actualEvent[property]).to.equal(expectedSdamEvent[property]);
}
return;
} else if (expectedEvent.topologyDescriptionChangedEvent) {
expect(actualEvent).to.be.instanceOf(TopologyDescriptionChangedEvent);

const actualTopChangedEvent = actualEvent as TopologyDescriptionChangedEvent;
const expectedSdamEvent = expectedEvent.topologyDescriptionChangedEvent;
for (const property of Object.keys(expectedSdamEvent)) {
expect(actualEvent[property]).to.equal(expectedSdamEvent[property]);

if (expectedSdamEvent.previousDescription?.type) {
expect(actualTopChangedEvent.previousDescription.type).to.equal(
expectedSdamEvent.previousDescription.type
);
}

if (expectedSdamEvent.newDescription?.type) {
expect(actualTopChangedEvent.newDescription.type).to.equal(
expectedSdamEvent.newDescription.type
);
}
return;
} else {
expect.fail(`Encountered unexpected event - ${inspect(actualEvent)}`);
}
Expand Down
6 changes: 4 additions & 2 deletions test/tools/unified-spec-runner/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ServerApiVersion,
SeverityLevel,
TagSet,
TopologyType as EventTopologyType,
W
} from '../../mongodb';
import { type TestConfiguration } from '../runner/config';
Expand Down Expand Up @@ -314,6 +315,7 @@ export interface ExpectedCmapEvent {
connectionCheckedOutEvent?: Record<string, never>;
connectionCheckedInEvent?: Record<string, never>;
}

export interface ExpectedSdamEvent {
serverDescriptionChangedEvent?: {
previousDescription?: {
Expand All @@ -336,10 +338,10 @@ export interface ExpectedSdamEvent {
topologyDescriptionChangedEvent?: {
topologyId?: any;
previousDescription?: {
type?: string;
type?: EventTopologyType;
};
newDescription?: {
type?: string;
type?: EventTopologyType;
};
};
topologyOpeningEvent?: {
Expand Down

0 comments on commit 27f832a

Please sign in to comment.