Skip to content

Commit a2eb3e1

Browse files
committed
fix unit test cases
1 parent 5140418 commit a2eb3e1

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

packages/@aws-cdk/aws-redshift-alpha/test/database-query-provider/privileges.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jest.mock('@aws-sdk/client-redshift-data', () => {
4040
});
4141

4242
import { handler as managePrivileges } from '../../lib/private/database-query-provider/privileges';
43+
import { makePhysicalId } from '../../lib/private/database-query-provider/util';
4344

4445
beforeEach(() => {
4546
jest.clearAllMocks();
@@ -61,6 +62,31 @@ describe('create', () => {
6162
Sql: `GRANT INSERT, SELECT ON ${tableName} TO ${username}`,
6263
}));
6364
});
65+
66+
test('serializes properties in statement when tableName in physical resource ID', async () => {
67+
const properties = {
68+
...resourceProperties,
69+
tablePrivileges: [{
70+
tableId,
71+
tableName: `${makePhysicalId(tableName, resourceProperties, requestId)}`,
72+
actions,
73+
}],
74+
};
75+
76+
const event = {
77+
...baseEvent,
78+
ResourceProperties: properties,
79+
StackId: 'xxxxx:' + requestId,
80+
};
81+
82+
await expect(managePrivileges(properties, event)).resolves.toEqual({
83+
PhysicalResourceId: 'clusterName:databaseName:username:requestId',
84+
});
85+
86+
expect(mockExecuteStatement).toHaveBeenCalledWith(expect.objectContaining({
87+
Sql: `GRANT INSERT, SELECT ON ${tableName} TO ${username}`,
88+
}));
89+
});
6490
});
6591

6692
describe('delete', () => {
@@ -79,6 +105,29 @@ describe('delete', () => {
79105
Sql: `REVOKE INSERT, SELECT ON ${tableName} FROM ${username}`,
80106
}));
81107
});
108+
109+
test('serializes properties in statement when tableName in physical resource ID', async () => {
110+
const properties = {
111+
...resourceProperties,
112+
tablePrivileges: [{
113+
tableId,
114+
tableName: `${makePhysicalId(tableName, resourceProperties, requestId)}`,
115+
actions,
116+
}],
117+
};
118+
119+
const event = {
120+
...baseEvent,
121+
ResourceProperties: properties,
122+
StackId: 'xxxxx:' + requestId,
123+
};
124+
125+
await managePrivileges(properties, event);
126+
127+
expect(mockExecuteStatement).toHaveBeenCalledWith(expect.objectContaining({
128+
Sql: `REVOKE INSERT, SELECT ON ${tableName} FROM ${username}`,
129+
}));
130+
});
82131
});
83132

84133
describe('update', () => {

packages/@aws-cdk/aws-redshift-alpha/test/database-query-provider/table.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('create', () => {
6161
const event = baseEvent;
6262

6363
await expect(manageTable(resourceProperties, event)).resolves.toEqual({
64-
PhysicalResourceId: 'clusterName:databaseName:tableNamePrefix:111111111111',
64+
PhysicalResourceId: 'clusterName:databaseName:tableNamePrefix111111111111:111111111111',
6565
});
6666
expect(mockExecuteStatement).toHaveBeenCalledWith(expect.objectContaining({
6767
Sql: `CREATE TABLE ${tableNamePrefix}${stackIdTruncated} (col1 varchar(1))`,

packages/@aws-cdk/aws-redshift-alpha/test/privileges.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('table privileges', () => {
7474
'username',
7575
],
7676
},
77-
tablePrivileges: [{ tableName: 'tableName', actions: ['SELECT', 'DELETE', 'INSERT'] }],
77+
tablePrivileges: [{ tableName: 'tableName', actions: ['INSERT', 'DELETE', 'SELECT'] }],
7878
});
7979
});
8080

0 commit comments

Comments
 (0)