Skip to content

Commit a84d220

Browse files
committed
add test cases
1 parent 495bfba commit a84d220

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

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

Lines changed: 1 addition & 6 deletions
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

Lines changed: 25 additions & 1 deletion
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,27 @@ 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+
'Profile instance profile2 not found'
386+
);
387+
}, 30000);
388+
389+
it('Should return default pool when password was not given', async () => {
390+
// Arrange
391+
mockDataSource = new MockCannerDataSource({}, '', [
392+
pg.getProfile('profile1'),
393+
]);
394+
await mockDataSource.activate();
395+
// Act
396+
const pool = mockDataSource.getPool('profile1');
397+
// Assert
398+
expect(pool).toBeDefined();
399+
}, 30000);

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

Lines changed: 1 addition & 6 deletions
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)