Skip to content

Commit

Permalink
SSMContextProviderPlugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviomacedo committed Nov 11, 2024
1 parent b2383fc commit 275e6b4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions packages/aws-cdk/test/context-providers/ssm-parameters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { GetParameterCommand } from '@aws-sdk/client-ssm';
import { SDK, SdkForEnvironment } from '../../lib';
import { SSMContextProviderPlugin } from '../../lib/context-providers/ssm-parameters';
import { FAKE_CREDENTIALS, MockSdkProvider, mockSSMClient, restoreSdkMocksToDefault } from '../util/mock-sdk';

const mockSDK = new (class extends MockSdkProvider {
public forEnvironment(): Promise<SdkForEnvironment> {
return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIALS, mockSDK.defaultRegion, {}), didAssumeRole: false });
}
})();

describe('ssmParameters', () => {
test('returns value', async () => {
restoreSdkMocksToDefault();
const provider = new SSMContextProviderPlugin(mockSDK);

mockSSMClient.on(GetParameterCommand).resolves({
Parameter: {
Value: 'bar',
},
});

// WHEN
const value = await provider.getValue({
account: '1234',
region: 'us-east-1',
parameterName: 'foo',
});

expect(value).toEqual('bar');
});

test('errors when parameter is not found', async () => {
restoreSdkMocksToDefault();
const provider = new SSMContextProviderPlugin(mockSDK);

const notFound = new Error('Parameter not found');
notFound.name = 'ParameterNotFound';
mockSSMClient.on(GetParameterCommand).rejects(notFound);

// WHEN
await expect(
provider.getValue({
account: '1234',
region: 'us-east-1',
parameterName: 'foo',
})).rejects.toThrow(/SSM parameter not available in account/);
});
});

0 comments on commit 275e6b4

Please sign in to comment.