diff --git a/lib/plugins/aws/configCredentials/awsConfigCredentials.test.js b/lib/plugins/aws/configCredentials/awsConfigCredentials.test.js index 2944e0ab3..21838e178 100644 --- a/lib/plugins/aws/configCredentials/awsConfigCredentials.test.js +++ b/lib/plugins/aws/configCredentials/awsConfigCredentials.test.js @@ -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); + }); + }); });