Skip to content

Commit 3e0b88e

Browse files
committed
test: fix unit test failure due to missing file
1 parent fb01d10 commit 3e0b88e

8 files changed

Lines changed: 61 additions & 20 deletions

common/lib/authentication/aws_secrets_manager_plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export class AwsSecretsManagerPlugin extends AbstractConnectionPlugin implements
141141
}
142142
}
143143
logger.debug(Messages.get("AwsSecretsManagerConnectionPlugin.unhandledError", error.name, error.message));
144+
throw error;
144145
}
145146
}
146147

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
export class StatusCacheItem<T> {
18+
readonly status: T;
19+
20+
constructor(status: T) {
21+
this.status = status;
22+
}
23+
}

tests/unit/batching_event_publisher.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class TestableEventPublisher extends BatchingEventPublisher {
3535
return this.pendingEvents.size;
3636
}
3737

38-
triggerSendMessages(): void {
39-
this.sendMessages();
38+
async triggerSendMessages(): Promise<void> {
39+
await this.sendMessages();
4040
}
4141
}
4242

@@ -52,7 +52,7 @@ describe("BatchingEventPublisher", () => {
5252
publisher = new TestableEventPublisher();
5353
processEventCalls = [];
5454
mockSubscriber = {
55-
processEvent: (event: Event) => {
55+
processEvent: async (event: Event) => {
5656
processEventCalls.push(event);
5757
}
5858
};
@@ -62,7 +62,7 @@ describe("BatchingEventPublisher", () => {
6262
publisher.releaseResources();
6363
});
6464

65-
it("should publish events to subscribers and deduplicate", () => {
65+
it("should publish events to subscribers and deduplicate", async () => {
6666
const eventSubscriptions = new Set([DataAccessEvent]);
6767

6868
publisher.subscribe(mockSubscriber, eventSubscriptions);
@@ -73,7 +73,7 @@ describe("BatchingEventPublisher", () => {
7373
publisher.publish(event);
7474
publisher.publish(event);
7575

76-
publisher.triggerSendMessages();
76+
await publisher.triggerSendMessages();
7777

7878
expect(publisher.pendingEventCount).toBe(0);
7979

@@ -82,7 +82,7 @@ describe("BatchingEventPublisher", () => {
8282

8383
publisher.unsubscribe(mockSubscriber, eventSubscriptions);
8484
publisher.publish(event);
85-
publisher.triggerSendMessages();
85+
await publisher.triggerSendMessages();
8686

8787
expect(publisher.pendingEventCount).toBe(0);
8888

@@ -105,23 +105,23 @@ describe("BatchingEventPublisher", () => {
105105
expect(publisher.pendingEventCount).toBe(0);
106106
});
107107

108-
it("should not deliver events to unsubscribed subscribers", () => {
108+
it("should not deliver events to unsubscribed subscribers", async () => {
109109
const eventSubscriptions = new Set([DataAccessEvent]);
110110

111111
publisher.subscribe(mockSubscriber, eventSubscriptions);
112112
publisher.unsubscribe(mockSubscriber, eventSubscriptions);
113113

114114
const event = new DataAccessEvent(TestDataClass, "key");
115115
publisher.publish(event);
116-
publisher.triggerSendMessages();
116+
await publisher.triggerSendMessages();
117117

118118
expect(processEventCalls.length).toBe(0);
119119
});
120120

121-
it("should handle multiple subscribers", () => {
121+
it("should handle multiple subscribers", async () => {
122122
const processEventCalls2: Event[] = [];
123123
const mockSubscriber2: EventSubscriber = {
124-
processEvent: (event: Event) => {
124+
processEvent: async (event: Event) => {
125125
processEventCalls2.push(event);
126126
}
127127
};
@@ -133,7 +133,7 @@ describe("BatchingEventPublisher", () => {
133133

134134
const event = new DataAccessEvent(TestDataClass, "key");
135135
publisher.publish(event);
136-
publisher.triggerSendMessages();
136+
await publisher.triggerSendMessages();
137137

138138
expect(processEventCalls.length).toBe(1);
139139
expect(processEventCalls2.length).toBe(1);

tests/unit/connection_plugin_chain_builder.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ const mockPluginServiceInstance: PluginService = instance(mockPluginService);
3737
const mockDefaultConnProvider: ConnectionProvider = mock(DriverConnectionProvider);
3838
const mockEffectiveConnProvider: ConnectionProvider = mock(DriverConnectionProvider);
3939

40+
const mockServicesContainer: FullServicesContainer = {
41+
pluginService: mockPluginServiceInstance,
42+
telemetryFactory: new NullTelemetryFactory()
43+
} as unknown as FullServicesContainer;
44+
4045
describe("testConnectionPluginChainBuilder", () => {
4146
beforeAll(() => {
4247
when(mockPluginService.getTelemetryFactory()).thenReturn(new NullTelemetryFactory());
@@ -51,7 +56,7 @@ describe("testConnectionPluginChainBuilder", () => {
5156
props.set(WrapperProperties.PLUGINS.name, plugins);
5257

5358
const result = await ConnectionPluginChainBuilder.getPlugins(
54-
mockPluginServiceInstance,
59+
mockServicesContainer,
5560
props,
5661
new ConnectionProviderManager(mockDefaultConnProvider, mockEffectiveConnProvider),
5762
null
@@ -70,7 +75,7 @@ describe("testConnectionPluginChainBuilder", () => {
7075
props.set(WrapperProperties.AUTO_SORT_PLUGIN_ORDER.name, false);
7176

7277
const result = await ConnectionPluginChainBuilder.getPlugins(
73-
mockPluginServiceInstance,
78+
mockServicesContainer,
7479
props,
7580
new ConnectionProviderManager(mockDefaultConnProvider, mockEffectiveConnProvider),
7681
null
@@ -89,7 +94,7 @@ describe("testConnectionPluginChainBuilder", () => {
8994
props.set(WrapperProperties.PLUGINS.name, "executeTime,connectTime,iam");
9095

9196
let result = await ConnectionPluginChainBuilder.getPlugins(
92-
mockPluginServiceInstance,
97+
mockServicesContainer,
9398
props,
9499
new ConnectionProviderManager(mockDefaultConnProvider, mockEffectiveConnProvider),
95100
null
@@ -104,7 +109,7 @@ describe("testConnectionPluginChainBuilder", () => {
104109
props.set(WrapperProperties.PLUGINS.name, "iam,executeTime,connectTime,failover");
105110

106111
result = await ConnectionPluginChainBuilder.getPlugins(
107-
mockPluginServiceInstance,
112+
mockServicesContainer,
108113
props,
109114
new ConnectionProviderManager(mockDefaultConnProvider, mockEffectiveConnProvider),
110115
null
@@ -125,7 +130,7 @@ describe("testConnectionPluginChainBuilder", () => {
125130
props.set(WrapperProperties.PLUGINS.name, "test");
126131

127132
const result = await ConnectionPluginChainBuilder.getPlugins(
128-
mockPluginServiceInstance,
133+
mockServicesContainer,
129134
props,
130135
new ConnectionProviderManager(mockDefaultConnProvider, mockEffectiveConnProvider),
131136
null

tests/unit/database_dialect.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { SimpleHostAvailabilityStrategy } from "../../common/lib/host_availabili
3030
import { ClientWrapper } from "../../common/lib/client_wrapper";
3131
import { RdsMultiAZClusterMySQLDatabaseDialect } from "../../mysql/lib/dialect/rds_multi_az_mysql_database_dialect";
3232
import { RdsMultiAZClusterPgDatabaseDialect } from "../../pg/lib/dialect/rds_multi_az_pg_database_dialect";
33+
import { GlobalAuroraMySQLDatabaseDialect } from "../../mysql/lib/dialect/global_aurora_mysql_database_dialect";
34+
import { GlobalAuroraPgDatabaseDialect } from "../../pg/lib/dialect/global_aurora_pg_database_dialect";
3335
import { DatabaseDialectManager } from "../../common/lib/database_dialect/database_dialect_manager";
3436
import { NodePostgresDriverDialect } from "../../pg/lib/dialect/node_postgres_driver_dialect";
3537
import { mock } from "ts-mockito";
@@ -49,14 +51,16 @@ const mysqlDialects: Map<DatabaseDialectCodes, DatabaseDialect> = new Map([
4951
[DatabaseDialectCodes.MYSQL, new MySQLDatabaseDialect()],
5052
[DatabaseDialectCodes.RDS_MYSQL, new RdsMySQLDatabaseDialect()],
5153
[DatabaseDialectCodes.AURORA_MYSQL, new AuroraMySQLDatabaseDialect()],
52-
[DatabaseDialectCodes.RDS_MULTI_AZ_MYSQL, new RdsMultiAZClusterMySQLDatabaseDialect()]
54+
[DatabaseDialectCodes.RDS_MULTI_AZ_MYSQL, new RdsMultiAZClusterMySQLDatabaseDialect()],
55+
[DatabaseDialectCodes.GLOBAL_AURORA_MYSQL, new GlobalAuroraMySQLDatabaseDialect()]
5356
]);
5457

5558
const pgDialects: Map<DatabaseDialectCodes, DatabaseDialect> = new Map([
5659
[DatabaseDialectCodes.PG, new PgDatabaseDialect()],
5760
[DatabaseDialectCodes.RDS_PG, new RdsPgDatabaseDialect()],
5861
[DatabaseDialectCodes.AURORA_PG, new AuroraPgDatabaseDialect()],
59-
[DatabaseDialectCodes.RDS_MULTI_AZ_PG, new RdsMultiAZClusterPgDatabaseDialect()]
62+
[DatabaseDialectCodes.RDS_MULTI_AZ_PG, new RdsMultiAZClusterPgDatabaseDialect()],
63+
[DatabaseDialectCodes.GLOBAL_AURORA_PG, new GlobalAuroraPgDatabaseDialect()]
6064
]);
6165

6266
const MYSQL_QUERY = "SHOW VARIABLES LIKE 'version_comment'";
@@ -287,6 +291,8 @@ describe("test database dialects", () => {
287291

288292
const mockClientWrapper: ClientWrapper = new PgClientWrapper(mockTargetClient, currentHostInfo, new Map<string, any>());
289293
const pluginService = new PluginServiceImpl(fullServicesContainer, mockClient, databaseType, expectedDialect!.dialects, props, mockDriverDialect);
294+
fullServicesContainer.hostListProviderService = pluginService;
295+
fullServicesContainer.pluginService = pluginService;
290296
await pluginService.updateDialect(mockClientWrapper);
291297
expect(pluginService.getDialect()).toBe(expectedDialectClass);
292298
});

tests/unit/failover2_plugin.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { MySQLClientWrapper } from "../../common/lib/mysql_client_wrapper";
4040
import { MySQL2DriverDialect } from "../../mysql/lib/dialect/mysql2_driver_dialect";
4141
import { DriverDialect } from "../../common/lib/driver_dialect/driver_dialect";
4242
import { Failover2Plugin } from "../../common/lib/plugins/failover2/failover2_plugin";
43+
import { FullServicesContainer } from "../../common/lib/utils/full_services_container";
4344

4445
const builder = new HostInfoBuilder({ hostAvailabilityStrategy: new SimpleHostAvailabilityStrategy() });
4546

@@ -57,7 +58,10 @@ const properties: Map<string, any> = new Map();
5758
let plugin: Failover2Plugin;
5859

5960
function initializePlugin(mockPluginServiceInstance: PluginService): void {
60-
plugin = new Failover2Plugin(mockPluginServiceInstance, properties, new RdsUtils());
61+
const mockContainer = {
62+
pluginService: mockPluginServiceInstance
63+
} as unknown as FullServicesContainer;
64+
plugin = new Failover2Plugin(mockContainer, properties, new RdsUtils());
6165
}
6266

6367
describe("reader failover handler", () => {

tests/unit/rds_host_list_provider.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ describe("testRdsHostListProvider", () => {
8282
when(mockPluginService.getCurrentClient()).thenReturn(instance(mockClient));
8383
when(mockClient.targetClient).thenReturn(mockClientWrapper);
8484
when(mockPluginService.getHostInfoBuilder()).thenReturn(new HostInfoBuilder({ hostAvailabilityStrategy: new SimpleHostAvailabilityStrategy() }));
85+
when(mockServiceContainer.hostListProviderService).thenReturn(instance(mockPluginService));
86+
when(mockServiceContainer.pluginService).thenReturn(instance(mockPluginService));
87+
when(mockServiceContainer.storageService).thenReturn(storageService);
8588
});
8689

8790
afterEach(async () => {

tests/unit/stale_dns_helper.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,5 @@ describe("test_stale_dns_helper", () => {
9191
targetInstance.notifyHostListChanged(changes);
9292

9393
expect(targetInstance["writerHostInfo"]).toBeNull();
94-
expect(targetInstance["writerHostAddress"]).toBe("");
9594
});
9695
});

0 commit comments

Comments
 (0)