Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aws test container #134

Merged
merged 5 commits into from
Jun 24, 2021
Merged

Aws test container #134

merged 5 commits into from
Jun 24, 2021

Conversation

belosh59
Copy link
Contributor

@belosh59 belosh59 commented Jun 4, 2021

Preliminary code which expose the current problems during test containers setup

  1. DynamoDB discovery is working, you could try it.

  2. At the moment we are creating dependencies for our selves (clients), so that it becomes difficult to inject localstack clients into the code. We need to expose private methods. But that also not working. Even deeper we also create such dependancy (S3 discovery is not working due to that perspective)
    Otherwise with current clients we are trying to reach the real AWS.

    1.1. I'm thinking about lightweight ServiceDiscovery pattern, but we need to keep clients being configured for different Regions being requested (e.g DynamoDB_AWS_GLOBAL / DynamoDB_US_WEST_1 )

  3. Seems like AWS Java SDK doesn't provide possibility to override AWS Endpoint globally for all clients link

  4. For a demo purpose we could setup localstack separately but we need to bypass localstack docker URL to reach it. Meanwhile there no possibility for that in code

Proposal:
We could create our AWS Clients based on env variable being passed on the stage of execution - > if nothing passed fallback to the default one - https://aws.amazon.com/

[To not merge yet]

@kickroot kickroot linked an issue Jun 5, 2021 that may be closed by this pull request
Copy link
Contributor

@kickroot kickroot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 1) I agree that you can use an env var to set the AWS endpoint. Something like MAGPIE_AWS_ENDPOINT. My first thought is to create a static utility method that will return the endpoint (defaulting to aws.amazon.com if not specified). Then each service will pass along that result to it's constructor.

For 3) Don't sweat the localstack demo env. We'll cross that bridge when we get to it.

magpie-aws/pom.xml Show resolved Hide resolved
@belosh59 belosh59 force-pushed the aws-test-container branch 2 times, most recently from 45083bc to defe72e Compare June 7, 2021 14:50
@belosh59
Copy link
Contributor Author

Added:

  • CF update-stack command usage for dynamic resource configuration for various tests using readable .yml template format
  • Fixed us-east-1 bucket bug processing
  • Added PR review fixes based on suggestion

@belosh59 belosh59 force-pushed the aws-test-container branch 2 times, most recently from 0c73d55 to d1388b1 Compare June 17, 2021 10:13
}

@Test
public void testEC2Discovery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whenRunningEc2DiscoveryShouldReturnInstanceEipSecurityGroupVolumeAndSnapshotInformation
It's probably good idea to split this test into 5. Each testing one thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got your point @PrzemyslawTusinski . We rather have here a complete testing for chosen component from magpie discovery perspective, instead of the unit testing when we could write tests isolated for various corner cases.

Splitting works good but we are going to expose our private methods for component discovery of the various aspects.
For example how we made with IAM - but I dont really like to change private method to protected just for the test availability.

I threat those tests as e2e AWS component discovery based on localstack. It like an IT with WireMocks when you passing from the controller request to database layer and back verifying the response.
In any case I propose to change method naming convention here once we will extend them with additional coverage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't meant exposing private methods.
I meant running full discovery in each test case, then during asset phase assert only one resource on each test case

}

@Test
public void testDynamoDBDiscovery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whenDiscoveringDynamoDbTablesShouldReturnProperContentInfo

}

@Test
public void testKMSDiscovery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better naming?

}

@Test
public void testCloudWatchDiscovery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better naming?

private ArgumentCaptor<MagpieEnvelope> envelopeCapture;

@Test
public void testAccountDiscovery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better naming?

}

@Test
public void testRoute53Discovery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better naming?

}

@Test
public void testS3Discovery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better naming?

}

@Test
public void testSNSDiscovery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better naming?

}

@Test
public void testSecretManagerDiscovery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better naming?

Comment on lines +50 to +51
assertTopic(invocations.get(0));
assertSubscription(invocations.get(1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider splitting this to 2 test cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be possible only if we will expose methods discoverTopics and discoverSubscriptions.
Not sure if we want it for test purpose. Initially I was designing cumulative approach to test input/output for available exposed method.
This decrease execution time and leading to the comparable coverage.
But it could fail because issue in either topic or subscription - at this point of IT testing that should be acceptable.
I will propose separate refactoring if required later.

@belosh59
Copy link
Contributor Author

Builded and tested against the real AWS Services

@belosh59 belosh59 merged commit 8642cad into main Jun 24, 2021
@belosh59 belosh59 deleted the aws-test-container branch June 24, 2021 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration Tests - Discovery
4 participants