Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/commands/flags/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class FlagOperations {
const cdkJsonContent = await fs.readFile(cdkJsonPath, 'utf-8');
const cdkJson = JSON.parse(cdkJsonContent);

if (flagNames.length === 1 && !params.safe && !params.all) {
if (flagNames.length === 1 && params.value !== undefined && !params.safe && !params.all) {
const boolValue = params.value === 'true';
cdkJson.context[String(flagNames[0])] = boolValue;
await this.ioHelper.defaults.info(`Setting flag '${flagNames}' to: ${boolValue}`);
Expand Down
34 changes: 34 additions & 0 deletions packages/aws-cdk/test/commands/flag-operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,40 @@ describe('modifyValues', () => {
requestResponseSpy.mockRestore();
});

test('sets a single unconfigured flag to its recommended value', async () => {
const flagName = '@aws-cdk/aws-cloudfront:defaultViewerProtocolPolicyRedirectToHttps';
const flags: FeatureFlag[] = [{
module: 'aws-cdk-lib',
name: flagName,
recommendedValue: true,
userValue: undefined,
explanation: 'Redirect viewer requests to HTTPS by default',
}];
const cdkJsonPath = await createCdkJsonFile({});

setupMockToolkitForPrototyping(mockToolkit);

const requestResponseSpy = jest.spyOn(ioHelper, 'requestResponse');
requestResponseSpy.mockResolvedValue(true);

const options: FlagsOptions = {
set: true,
unconfigured: true,
recommended: true,
};

const flagOperations = new FlagCommandHandler(flags, ioHelper, options, mockToolkit);
await flagOperations.processFlagsCommand();

const updatedContent = await fs.promises.readFile(cdkJsonPath, 'utf-8');
const updatedJson = JSON.parse(updatedContent);

expect(updatedJson.context[flagName]).toBe(true);

await cleanupCdkJsonFile(cdkJsonPath);
requestResponseSpy.mockRestore();
});

test('sets all flags to recommended values', async () => {
const cdkJsonPath = await createCdkJsonFile({
'@aws-cdk/core:testFlag': false,
Expand Down
Loading