-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into updateDatadogDefaultFilter
- Loading branch information
Showing
42 changed files
with
2,244 additions
and
1,089 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
plugins/backend/catalog-backend-module-aws/src/providers/AWSSNSTopicProvider.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2021 Larder Software Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { SNS, ListTopicsCommand, Topic } from '@aws-sdk/client-sns'; | ||
import { STS, GetCallerIdentityCommand } from '@aws-sdk/client-sts'; | ||
|
||
import { mockClient } from 'aws-sdk-client-mock'; | ||
import { createLogger, transports } from 'winston'; | ||
import { AWSSNSTopicProvider } from './AWSSNSTopicProvider'; | ||
import { ConfigReader } from '@backstage/config'; | ||
import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; | ||
|
||
const sns = mockClient(SNS); | ||
const sts = mockClient(STS); | ||
|
||
const logger = createLogger({ | ||
transports: [new transports.Console({ silent: true })], | ||
}); | ||
|
||
describe('AWSSNSTopicProvider', () => { | ||
const config = new ConfigReader({ | ||
accountId: '123456789012', | ||
roleName: 'arn:aws:iam::123456789012:role/role1', | ||
region: 'eu-west-1', | ||
}); | ||
|
||
beforeEach(() => { | ||
sts.on(GetCallerIdentityCommand).resolves({}); | ||
sns.reset(); // Ensure the mock client is reset before each test | ||
}); | ||
|
||
describe('when there are no SNS topics', () => { | ||
beforeEach(() => { | ||
sns.on(ListTopicsCommand).resolves({ | ||
Topics: [], | ||
}); | ||
}); | ||
|
||
it('creates no SNS topics', async () => { | ||
const entityProviderConnection: EntityProviderConnection = { | ||
applyMutation: jest.fn(), | ||
refresh: jest.fn(), | ||
}; | ||
const provider = AWSSNSTopicProvider.fromConfig(config, { logger }); | ||
provider.connect(entityProviderConnection); | ||
await provider.run(); | ||
expect(entityProviderConnection.applyMutation).toHaveBeenCalledWith({ | ||
type: 'full', | ||
entities: [], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when there are SNS topics', () => { | ||
beforeEach(() => { | ||
sns.on(ListTopicsCommand).resolves({ | ||
Topics: [ | ||
{ | ||
TopicArn: 'arn:aws:sns:eu-west-1:123456789012:example-topic', | ||
} as Partial<Topic> as any, | ||
], | ||
}); | ||
}); | ||
|
||
it('creates SNS topic entities', async () => { | ||
const entityProviderConnection: EntityProviderConnection = { | ||
applyMutation: jest.fn(), | ||
refresh: jest.fn(), | ||
}; | ||
const provider = AWSSNSTopicProvider.fromConfig(config, { logger }); | ||
provider.connect(entityProviderConnection); | ||
await provider.run(); | ||
expect(entityProviderConnection.applyMutation).toHaveBeenCalledWith({ | ||
type: 'full', | ||
entities: [ | ||
expect.objectContaining({ | ||
entity: expect.objectContaining({ | ||
kind: 'Resource', | ||
metadata: expect.objectContaining({ | ||
name: 'example-topic', | ||
title: 'example-topic', | ||
annotations: expect.objectContaining({ | ||
'backstage.io/view-url': | ||
'https://console.aws.amazon.com/sns/v3/home?region=eu-west-1#/topic/arn:aws:sns:eu-west-1:123456789012:example-topic', | ||
}), | ||
}), | ||
}), | ||
}), | ||
], | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.