Skip to content

Commit 720cf68

Browse files
authored
fix(integ-runner): --profile not working with toolkit-lib engine (#996)
Fixes #993 This change adds `profile` support to the toolkit-lib engine in the integ-runner package. The profile option is now passed through from the IntegRunnerOptions to the ToolkitLibEngineOptions and ultimately to the BaseCredentials configuration. This allows users to specify which AWS profile to use when running integration tests with the toolkit-lib engine, providing consistency with other authentication options already available in the integ-runner. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 8ac049e commit 720cf68

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

packages/@aws-cdk/integ-runner/lib/engines/toolkit-lib.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ export interface ToolkitLibEngineOptions {
3333
* The region the CDK app should synthesize itself for
3434
*/
3535
readonly region: string;
36+
37+
/**
38+
* The AWS profile to use when authenticating
39+
*
40+
* @default - no profile is passed, the default profile is used
41+
*/
42+
readonly profile?: string;
3643
}
3744

3845
/**
@@ -56,6 +63,7 @@ export class ToolkitLibRunnerEngine implements ICdk {
5663
ioHost: this.showOutput ? this.ioHost : new NoopIoHost(),
5764
sdkConfig: {
5865
baseCredentials: BaseCredentials.awsCliCompatible({
66+
profile: options.profile,
5967
defaultRegion: options.region,
6068
}),
6169
},

packages/@aws-cdk/integ-runner/lib/runner/engine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export function makeEngine(options: IntegRunnerOptions): ICdk {
2020
showOutput: options.showOutput,
2121
env: options.env,
2222
region: options.region,
23+
profile: options.profile,
2324
});
2425
case 'cli-wrapper':
2526
default:

packages/@aws-cdk/integ-runner/test/engines/toolkit-lib.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
22
import { HotswapMode } from '@aws-cdk/cdk-cli-wrapper';
3-
import { Toolkit } from '@aws-cdk/toolkit-lib';
3+
import { Toolkit, BaseCredentials } from '@aws-cdk/toolkit-lib';
44
import { ToolkitLibRunnerEngine } from '../../lib/engines/toolkit-lib';
55

66
jest.mock('@aws-cdk/toolkit-lib');
77

88
const MockedToolkit = Toolkit as jest.MockedClass<typeof Toolkit>;
9+
const MockedBaseCredentials = BaseCredentials as jest.Mocked<typeof BaseCredentials>;
910

1011
describe('ToolkitLibRunnerEngine', () => {
1112
let mockToolkit: jest.Mocked<Toolkit>;
@@ -230,6 +231,21 @@ describe('ToolkitLibRunnerEngine', () => {
230231
}));
231232
});
232233

234+
it('should pass profile to BaseCredentials', () => {
235+
MockedBaseCredentials.awsCliCompatible = jest.fn();
236+
237+
new ToolkitLibRunnerEngine({
238+
workingDirectory: '/test',
239+
region: 'us-dummy-1',
240+
profile: 'test-profile',
241+
});
242+
243+
expect(MockedBaseCredentials.awsCliCompatible).toHaveBeenCalledWith({
244+
profile: 'test-profile',
245+
defaultRegion: 'us-dummy-1',
246+
});
247+
});
248+
233249
it('should throw error when no app is provided', async () => {
234250
await expect(engine.synth({} as any)).rejects.toThrow('No app provided');
235251
});

0 commit comments

Comments
 (0)