Skip to content

Commit

Permalink
test: remove hardcoded test from github issue tst 2096 (#6463)
Browse files Browse the repository at this point in the history
the test had assumed the username, password, host, and port of
the mysql server

this update changes that so the test instead uses the config properly
while still checking that the test works as expected
  • Loading branch information
imnotjames committed Aug 2, 2020
1 parent f270c0b commit 33041cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/github-issues/114/issue-114.ts
Expand Up @@ -7,7 +7,7 @@ describe.skip("github issues > #114 Can not be parsed correctly the URL of pg.",

let connection: Connection;
before(() => {
connection = new Connection({
connection = new Connection({ // Dummy Connection, won't be established
type: "postgres",
url: "postgres://test:test@localhost:5432/test",
});
Expand Down
17 changes: 15 additions & 2 deletions test/github-issues/2096/issue-2096.ts
Expand Up @@ -2,17 +2,30 @@ import "reflect-metadata";
import { expect } from "chai";
import { createConnection } from "../../../src";
import { getTypeOrmConfig } from "../../utils/test-utils";
import {MysqlConnectionOptions} from "../../../src/driver/mysql/MysqlConnectionOptions";

describe("github issues > #2096 [mysql] Database name isn't read from url", () => {
it("should be possible to define a database by connection url for mysql", async () => {
const config = getTypeOrmConfig();

// it is important to synchronize here, to trigger EntityMetadataValidator.validate
// that previously threw the error where the database on the driver object was undefined
if (config.find(c => c.name === "mysql" && !c.skip)) {
const mysqlConfig: MysqlConnectionOptions = config.find(c => c.name === "mysql" && !c.skip) as MysqlConnectionOptions;

if (mysqlConfig) {
const {
username,
password,
host,
port,
database
} = mysqlConfig;

const url = `mysql://${username}:${password}@${host}:${port}/${database}`

const connection = await createConnection({
name: "#2096",
url: "mysql://root:admin@localhost:3306/test",
url,
entities: [__dirname + "/entity/*{.js,.ts}"],
synchronize: true,
type: "mysql"
Expand Down

0 comments on commit 33041cc

Please sign in to comment.