Fix test
This commit is contained in:
+51
-1
@@ -19,7 +19,7 @@ import { AwsOrganizationCloudAccountProcessor } from './AwsOrganizationCloudAcco
|
||||
describe('AwsOrganizationCloudAccountProcessor', () => {
|
||||
describe('readLocation', () => {
|
||||
const processor = new AwsOrganizationCloudAccountProcessor();
|
||||
const location = { type: 'aws-cloud-accounts', target: 'b' };
|
||||
const location = { type: 'aws-cloud-accounts', target: '' };
|
||||
const emit = jest.fn();
|
||||
const listAccounts = jest.fn();
|
||||
|
||||
@@ -68,5 +68,55 @@ describe('AwsOrganizationCloudAccountProcessor', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('filters out accounts not in specified location target', async () => {
|
||||
const location = { type: 'aws-cloud-accounts', target: 'o-1vl18kc5a3' };
|
||||
listAccounts.mockImplementation(() => {
|
||||
return {
|
||||
async promise() {
|
||||
return {
|
||||
Accounts: [
|
||||
{
|
||||
Arn:
|
||||
'arn:aws:organizations::192594491037:account/o-1vl18kc5a3/957140518395',
|
||||
Name: 'testaccount',
|
||||
},
|
||||
{
|
||||
Arn:
|
||||
'arn:aws:organizations::192594491037:account/o-zzzzzzzzz/957140518395',
|
||||
Name: 'testaccount2',
|
||||
},
|
||||
],
|
||||
NextToken: undefined,
|
||||
};
|
||||
},
|
||||
};
|
||||
});
|
||||
await processor.readLocation(location, false, emit);
|
||||
expect(emit).toBeCalledTimes(1);
|
||||
expect(emit).toBeCalledWith({
|
||||
type: 'entity',
|
||||
location,
|
||||
entity: {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
annotations: {
|
||||
'amazonaws.com/arn':
|
||||
'arn:aws:organizations::192594491037:account/o-1vl18kc5a3/957140518395',
|
||||
'amazonaws.com/account-id': '957140518395',
|
||||
'amazonaws.com/organization-id': 'o-1vl18kc5a3',
|
||||
},
|
||||
name: 'testaccount',
|
||||
namespace: 'default',
|
||||
},
|
||||
spec: {
|
||||
type: 'cloud-account',
|
||||
lifecycle: 'unknown',
|
||||
owner: 'unknown',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+7
-5
@@ -26,7 +26,9 @@ import { CatalogProcessor, CatalogProcessorEmit } from './types';
|
||||
const AWS_ORGANIZATION_REGION = 'us-east-1';
|
||||
const LOCATION_TYPE = 'aws-cloud-accounts';
|
||||
|
||||
const ORGANIZATION_ANNOTATION = 'amazonaws.com/organization-id';
|
||||
const ACCOUNTID_ANNOTATION: string = 'amazonaws.com/account-id';
|
||||
const ARN_ANNOTATION: string = 'amazonaws.com/arn';
|
||||
const ORGANIZATION_ANNOTATION: string = 'amazonaws.com/organization-id';
|
||||
|
||||
/**
|
||||
* A processor for ingesting AWS Accounts from AWS Organizations.
|
||||
@@ -86,9 +88,9 @@ export class AwsOrganizationCloudAccountProcessor implements CatalogProcessor {
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
annotations: {
|
||||
'amazonaws.com/arn': account.Arn || '',
|
||||
'amazonaws.com/account-id': accountId,
|
||||
'amazonaws.com/organization-id': organizationId,
|
||||
[ACCOUNTID_ANNOTATION]: accountId,
|
||||
[ARN_ANNOTATION]: account.Arn || '',
|
||||
[ORGANIZATION_ANNOTATION]: organizationId,
|
||||
},
|
||||
name: this.normalizeName(account.Name || ''),
|
||||
namespace: 'default',
|
||||
@@ -117,7 +119,7 @@ export class AwsOrganizationCloudAccountProcessor implements CatalogProcessor {
|
||||
if (entity.metadata.annotations) {
|
||||
return (
|
||||
entity.metadata.annotations[ORGANIZATION_ANNOTATION] ===
|
||||
location.type
|
||||
location.target
|
||||
);
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user