Skip to content
Merged
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
40 changes: 21 additions & 19 deletions test/unit/src/state/S3StateStorage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,32 @@ describe('test/unit/src/state/S3StateStorage.test.js', () => {
});
});

it('passes full client config into the S3 client constructor', () => {
const S3 = sinon.stub().returns({});
const S3StateStorageWithStubbedClient = proxyquire
.noCallThru()
.load('../../../../src/state/S3StateStorage', {
'@aws-sdk/client-s3': { S3 },
describe('S3 client config', () => {
it('passes full client config into the S3 client constructor', () => {
const S3 = sinon.stub().returns({});
const S3StateStorageWithStubbedClient = proxyquire
.noCallThru()
.load('../../../../src/state/S3StateStorage', {
'@aws-sdk/client-s3': { S3 },
});

const stateStorage = new S3StateStorageWithStubbedClient({
bucketName,
stateKey,
region: 'eu-central-1',
clientConfig: {
region: 'eu-central-1',
credentials: 'creds',
retryMode: 'standard',
},
});

const stateStorage = new S3StateStorageWithStubbedClient({
bucketName,
stateKey,
region: 'eu-central-1',
clientConfig: {
expect(stateStorage).to.be.instanceOf(S3StateStorageWithStubbedClient);
expect(S3).to.have.been.calledOnceWithExactly({
region: 'eu-central-1',
credentials: 'creds',
retryMode: 'standard',
},
});

expect(stateStorage).to.be.instanceOf(S3StateStorageWithStubbedClient);
expect(S3).to.have.been.calledOnceWithExactly({
region: 'eu-central-1',
credentials: 'creds',
retryMode: 'standard',
});
});
});

Expand Down
142 changes: 66 additions & 76 deletions test/unit/src/state/get-s3-state-storage-from-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,51 @@ const sinon = require('sinon');

const expect = chai.expect;

describe('test/unit/src/state/get-s3-state-storage-from-config.test.js', () => {
afterEach(() => {
sinon.restore();
});
const loadGetS3StateStorageFromConfig = ({
getStateBucketName = sinon.stub().resolves('bucket'),
getConfiguredStateBucketName = sinon.stub().returns(null),
getStateBucketRegion = sinon.stub().resolves('us-east-1'),
getAwsClientConfig = sinon.stub().returns({ region: 'us-east-1' }),
} = {}) => {
class S3StateStorage {
constructor(config) {
this.config = config;
}
}

const getS3StateStorageFromConfig = proxyquire
.noCallThru()
.load('../../../../src/state/get-s3-state-storage-from-config', {
'../utils/aws': { getAwsClientConfig },
'./S3StateStorage': S3StateStorage,
'./utils/get-configured-state-bucket-name': getConfiguredStateBucketName,
'./utils/get-state-bucket-name': getStateBucketName,
'./utils/get-state-bucket-region': getStateBucketRegion,
});

return {
getS3StateStorageFromConfig,
getStateBucketName,
getConfiguredStateBucketName,
getStateBucketRegion,
getAwsClientConfig,
};
};

describe('test/unit/src/state/get-s3-state-storage-from-config.test.js', () => {
it('uses us-east-1 for compose-managed buckets', async () => {
const getStateBucketName = sinon.stub().resolves('managed-bucket');
const getConfiguredStateBucketName = sinon.stub().returns(null);
const getStateBucketRegion = sinon.stub();
const awsClientConfig = { region: 'us-east-1', credentials: 'creds', retryMode: 'standard' };
const getAwsClientConfig = sinon.stub().returns(awsClientConfig);

class S3StateStorage {
constructor(config) {
this.config = config;
}
}

const getS3StateStorageFromConfig = proxyquire
.noCallThru()
.load('../../../../src/state/get-s3-state-storage-from-config', {
'../utils/aws': { getAwsClientConfig },
'./S3StateStorage': S3StateStorage,
'./utils/get-configured-state-bucket-name': getConfiguredStateBucketName,
'./utils/get-state-bucket-name': getStateBucketName,
'./utils/get-state-bucket-region': getStateBucketRegion,
});
const {
getS3StateStorageFromConfig,
getStateBucketName,
getConfiguredStateBucketName,
getStateBucketRegion,
getAwsClientConfig,
} = loadGetS3StateStorageFromConfig({
getStateBucketName: sinon.stub().resolves('managed-bucket'),
getStateBucketRegion: sinon.stub(),
getAwsClientConfig: sinon.stub().returns(awsClientConfig),
});

const stateStorage = await getS3StateStorageFromConfig(
{ backend: 's3', prefix: 'custom', profile: 'team' },
Expand Down Expand Up @@ -66,22 +84,12 @@ describe('test/unit/src/state/get-s3-state-storage-from-config.test.js', () => {
const getStateBucketRegion = sinon.stub().resolves('eu-central-1');
const awsClientConfig = { region: 'eu-central-1', credentials: 'creds', retryMode: 'standard' };
const getAwsClientConfig = sinon.stub().returns(awsClientConfig);

class S3StateStorage {
constructor(config) {
this.config = config;
}
}

const getS3StateStorageFromConfig = proxyquire
.noCallThru()
.load('../../../../src/state/get-s3-state-storage-from-config', {
'../utils/aws': { getAwsClientConfig },
'./S3StateStorage': S3StateStorage,
'./utils/get-configured-state-bucket-name': getConfiguredStateBucketName,
'./utils/get-state-bucket-name': getStateBucketName,
'./utils/get-state-bucket-region': getStateBucketRegion,
});
const { getS3StateStorageFromConfig } = loadGetS3StateStorageFromConfig({
getStateBucketName,
getConfiguredStateBucketName,
getStateBucketRegion,
getAwsClientConfig,
});

const stateStorage = await getS3StateStorageFromConfig(stateConfiguration, { stage: 'dev' });

Expand Down Expand Up @@ -114,22 +122,12 @@ describe('test/unit/src/state/get-s3-state-storage-from-config.test.js', () => {
const getStateBucketRegion = sinon.stub().resolves('eu-central-1');
const awsClientConfig = { region: 'eu-central-1', credentials: 'creds', retryMode: 'standard' };
const getAwsClientConfig = sinon.stub().returns(awsClientConfig);

class S3StateStorage {
constructor(config) {
this.config = config;
}
}

const getS3StateStorageFromConfig = proxyquire
.noCallThru()
.load('../../../../src/state/get-s3-state-storage-from-config', {
'../utils/aws': { getAwsClientConfig },
'./S3StateStorage': S3StateStorage,
'./utils/get-configured-state-bucket-name': getConfiguredStateBucketName,
'./utils/get-state-bucket-name': getStateBucketName,
'./utils/get-state-bucket-region': getStateBucketRegion,
});
const { getS3StateStorageFromConfig } = loadGetS3StateStorageFromConfig({
getStateBucketName,
getConfiguredStateBucketName,
getStateBucketRegion,
getAwsClientConfig,
});

const stateStorage = await getS3StateStorageFromConfig(stateConfiguration, { stage: 'dev' });

Expand All @@ -152,26 +150,18 @@ describe('test/unit/src/state/get-s3-state-storage-from-config.test.js', () => {
});

it('rejects invalid stage before composing S3 state key', async () => {
const getStateBucketName = sinon.stub();
const getConfiguredStateBucketName = sinon.stub();
const getStateBucketRegion = sinon.stub();
const getAwsClientConfig = sinon.stub();

class S3StateStorage {
constructor(config) {
this.config = config;
}
}

const getS3StateStorageFromConfig = proxyquire
.noCallThru()
.load('../../../../src/state/get-s3-state-storage-from-config', {
'../utils/aws': { getAwsClientConfig },
'./S3StateStorage': S3StateStorage,
'./utils/get-configured-state-bucket-name': getConfiguredStateBucketName,
'./utils/get-state-bucket-name': getStateBucketName,
'./utils/get-state-bucket-region': getStateBucketRegion,
});
const {
getS3StateStorageFromConfig,
getStateBucketName,
getConfiguredStateBucketName,
getStateBucketRegion,
getAwsClientConfig,
} = loadGetS3StateStorageFromConfig({
getStateBucketName: sinon.stub(),
getConfiguredStateBucketName: sinon.stub(),
getStateBucketRegion: sinon.stub(),
getAwsClientConfig: sinon.stub(),
});

await expect(
getS3StateStorageFromConfig({ backend: 's3' }, { stage: 'foo/../../tmp/x' })
Expand Down
Loading
Loading