Skip to content

Commit 6d02de5

Browse files
committed
add test cases
1 parent 6a78c61 commit 6d02de5

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

packages/extension-driver-canner/src/lib/cannerDataSource.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,7 @@ export class CannerDataSource extends DataSource<any, PGOptions> {
170170
const userPoolKey = this.getUserPoolKey(password, database);
171171
if (this.UserPool.has(userPoolKey)) {
172172
const userPool = this.UserPool.get(userPoolKey);
173-
if (!userPool) {
174-
throw new InternalError(
175-
`User pool ${userPoolKey} is not a Pool instance`
176-
);
177-
}
178-
return userPool;
173+
return userPool!;
179174
}
180175
const pool = new Pool({ ...poolOptions, password: password });
181176
this.UserPool.set(userPoolKey, pool);

packages/extension-driver-canner/test/cannerDataSource.spec.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ it('Should return the same pool when the profile and authentication is the same'
348348
expect(pool1 === pool2).toBeTruthy();
349349
}, 30000);
350350

351-
it('Should return different pool if authentication exist in headers even the profile is the same', async () => {
351+
it('Should return new user pool if user pool not exist', async () => {
352352
// Arrange
353353
mockDataSource = new MockCannerDataSource({}, '', [
354354
pg.getProfile('profile1'),
@@ -373,3 +373,25 @@ it('Should return different pool with different authentication even the profile
373373
// Assert
374374
expect(pool1 === pool2).toBeFalsy();
375375
}, 30000);
376+
377+
it('Should throw error when the profile is not exist', async () => {
378+
// Arrange
379+
mockDataSource = new MockCannerDataSource({}, '', [
380+
pg.getProfile('profile1'),
381+
]);
382+
await mockDataSource.activate();
383+
// Act, Assert
384+
expect(() => mockDataSource.getPool('profile2')).toThrow();
385+
}, 30000);
386+
387+
it('Should return default pool when password was not given', async () => {
388+
// Arrange
389+
mockDataSource = new MockCannerDataSource({}, '', [
390+
pg.getProfile('profile1'),
391+
]);
392+
await mockDataSource.activate();
393+
// Act
394+
const pool = mockDataSource.getPool('profile1');
395+
// Assert
396+
expect(pool).toBeDefined();
397+
}, 30000);

packages/extension-driver-canner/test/mock/mockCannerDataSource.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ export class MockCannerDataSource extends CannerDataSource {
1616
const userPoolKey = this.getUserPoolKey(password, database);
1717
if (this.UserPool.has(userPoolKey)) {
1818
const userPool = this.UserPool.get(userPoolKey);
19-
if (!userPool) {
20-
throw new InternalError(
21-
`User pool ${userPoolKey} is not a Pool instance`
22-
);
23-
}
24-
return userPool;
19+
return userPool!;
2520
}
2621
const pool = new Pool({ ...poolOptions, password: password });
2722
this.UserPool.set(userPoolKey, pool);

0 commit comments

Comments
 (0)