|
| 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 | +import { mock } from "ts-mockito"; |
| 18 | +import { MySQL2DriverDialect } from "../../mysql/lib/dialect/mysql2_driver_dialect"; |
| 19 | +import { HostInfo } from "../../common/lib/host_info"; |
| 20 | +import { UnsupportedMethodError } from "../../common/lib/utils/errors"; |
| 21 | +import { NodePostgresDriverDialect } from "../../pg/lib/dialect/node_postgres_driver_dialect"; |
| 22 | + |
| 23 | +const mockHostInfo: HostInfo = mock(HostInfo); |
| 24 | +const emptyProps: Map<string, any> = new Map<string, any>(); |
| 25 | + |
| 26 | +describe("driverDialectTest", () => { |
| 27 | + it("test_connectWithKeepAliveProps_MySQL_shouldThrow", async () => { |
| 28 | + const keepAliveProps = new Map<string, any>([ |
| 29 | + ["keepAlive", true], |
| 30 | + ["keepAliveInitialDelayMillis", 1234] |
| 31 | + ]); |
| 32 | + |
| 33 | + const props = new Map<string, any>([["wrapperKeepAliveProperties", keepAliveProps]]); |
| 34 | + |
| 35 | + const dialect = new MySQL2DriverDialect(); |
| 36 | + const unsupportedError = new UnsupportedMethodError("Keep alive configuration is not supported for MySQL2."); |
| 37 | + |
| 38 | + await expect(dialect.connect(mockHostInfo, props)).rejects.toThrow(unsupportedError); |
| 39 | + |
| 40 | + const keepAliveObj = { |
| 41 | + keepAlive: true, |
| 42 | + keepAliveInitialDelayMillis: 1234 |
| 43 | + }; |
| 44 | + |
| 45 | + const propsWithObj = new Map<string, any>([["wrapperKeepAliveProperties", keepAliveObj]]); |
| 46 | + |
| 47 | + await expect(dialect.connect(mockHostInfo, propsWithObj)).rejects.toThrow(unsupportedError); |
| 48 | + }); |
| 49 | + |
| 50 | + it("test_connectWithKeepAliveProps_PG_shouldSucceed", async () => { |
| 51 | + const keepAliveMap = new Map<string, any>([ |
| 52 | + ["keepAlive", true], |
| 53 | + ["keepAliveInitialDelayMillis", 1234] |
| 54 | + ]); |
| 55 | + |
| 56 | + const dialect = new NodePostgresDriverDialect(); |
| 57 | + |
| 58 | + dialect.setKeepAliveProperties(emptyProps, keepAliveMap); |
| 59 | + expect(emptyProps.get("keepAlive")).toBe(true); |
| 60 | + expect(emptyProps.get("keepAliveInitialDelayMillis")).toBe(1234); |
| 61 | + |
| 62 | + emptyProps.clear(); |
| 63 | + |
| 64 | + const keepAliveObj = { |
| 65 | + keepAlive: true, |
| 66 | + keepAliveInitialDelayMillis: 1234 |
| 67 | + }; |
| 68 | + |
| 69 | + dialect.setKeepAliveProperties(emptyProps, keepAliveObj); |
| 70 | + expect(emptyProps.get("keepAlive")).toBe(true); |
| 71 | + expect(emptyProps.get("keepAliveInitialDelayMillis")).toBe(1234); |
| 72 | + }); |
| 73 | +}); |
0 commit comments