add tests for awsConfigCredentials methods

This commit is contained in:
Gharsallah Mohamed 2017-06-27 11:28:10 +01:00
parent a0b1e33724
commit bc9e7c5136

View File

@ -216,4 +216,61 @@ describe('AwsConfigCredentials', () => {
});
});
});
describe('#getCredentials()', () => {
it('should load credentials file and return the credentials lines', () => {
fse.outputFileSync(credentialsFilePath, credentialsFileContent);
const credentials = awsConfigCredentials.getCredentials();
expect(credentials[0]).to.equal('[my-profile]');
expect(credentials[1]).to.equal('aws_access_key_id = my-old-profile-key');
});
it('should return an empty array if the file is empty', () => {
const credentials = awsConfigCredentials.getCredentials();
expect(credentials.length).to.equal(0);
});
});
describe('#getProfileBoundaries()', () => {
it('should return the start and end numbers of the profile', () => {
awsConfigCredentials.options.profile = 'my-profile';
awsConfigCredentials.credentials = [
'[my-profile]',
'aws_access_key_id = my-other-profile-key',
];
const profileBoundaries = awsConfigCredentials.getProfileBoundaries();
expect(profileBoundaries.start).to.equal(0);
expect(profileBoundaries.end).to.equal(2);
});
it('should set the start property to -1 if the profile was not found', () => {
awsConfigCredentials.options.profile = 'my-not-yet-saved-profile';
awsConfigCredentials.credentials = [
'[my-profile]',
'aws_access_key_id = my-other-profile-key',
];
const profileBoundaries = awsConfigCredentials.getProfileBoundaries();
expect(profileBoundaries.start).to.equal(-1);
});
it('should set the end to the credentials lentgh if no other profile was found', () => {
awsConfigCredentials.options.profile = 'my-profile';
awsConfigCredentials.credentials = [
'[my-profile]',
'aws_access_key_id = my-other-profile-key',
'# a comment',
'aws_secret_access_key = my-profile-secret',
];
const profileBoundaries = awsConfigCredentials.getProfileBoundaries();
expect(profileBoundaries.end).to.equal(4);
});
});
});