Skip to content

Reenable AwsIntegrationTest On Main #2227

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<google-api-services-iam.version>v1-rev20201112-1.30.10</google-api-services-iam.version>
<testcontainers.version>1.17.3</testcontainers.version>
<wiremock.version>2.31.0</wiremock.version>
<spring-cloud-aws.version>3.0.0-RC2</spring-cloud-aws.version><!-- @releaser:version-check-off -->
<spring-cloud-aws.version>3.0.0</spring-cloud-aws.version>
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
<maven-checkstyle-plugin.failsOnViolation>true
</maven-checkstyle-plugin.failsOnViolation>
Expand Down
5 changes: 5 additions & 0 deletions spring-cloud-config-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@
<artifactId>zipkin-sender-urlconnection</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-s3</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
package org.springframework.cloud.config.server;

import java.io.IOException;
import java.util.Optional;

import io.awspring.cloud.s3.InMemoryBufferingS3OutputStreamProvider;
import io.awspring.cloud.s3.PropertiesS3ObjectContentTypeResolver;
import io.awspring.cloud.s3.S3ObjectContentTypeResolver;
import io.awspring.cloud.s3.S3OutputStreamProvider;
import io.awspring.cloud.s3.S3ProtocolResolver;
import org.json.JSONException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -27,14 +33,18 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.test.TestConfigServerApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.test.util.TestSocketUtils;
import org.springframework.web.client.RestTemplate;

Expand All @@ -58,7 +68,7 @@ public class AwsS3IntegrationTests {

@BeforeAll
public static void startConfigServer() throws IOException, InterruptedException, JSONException {
server = SpringApplication.run(new Class[] { TestConfigServerApplication.class },
server = SpringApplication.run(new Class[] { TestConfigServerApplication.class, S3AutoConfiguration.class },
new String[] { "--spring.config.name=server", "--spring.profiles.active=awss3",
"--server.port=" + configServerPort,
"--spring.cloud.config.server.awss3.endpoint="
Expand All @@ -71,7 +81,7 @@ public static void startConfigServer() throws IOException, InterruptedException,
"--spring.cloud.aws.credentials.secret-key=" + localstack.getSecretKey(),
"--spring.cloud.aws.region.static=" + localstack.getRegion() });

if (server.containsBean(S3Client.class.getName())) {
if (server.getBeanNamesForType(S3Client.class).length > 0) {
s3Client = server.getBean(S3Client.class);
s3Client.createBucket((request) -> request.bucket("test-bucket"));
s3Client.putObject((request) -> request.bucket("test-bucket").key("data.txt"),
Expand All @@ -86,8 +96,6 @@ public static void startConfigServer() throws IOException, InterruptedException,

@Test
@Disabled
// TODO uncomment when we have an RC or GA release of Spring Cloud AWS with this fix
// https://github.com/awspring/spring-cloud-aws/pull/652
public void context() throws IOException {
RestTemplate rest = new RestTemplateBuilder().build();
String configServerUrl = "http://localhost:" + configServerPort;
Expand All @@ -104,4 +112,25 @@ public static void after() {
server.close();
}

@Import(S3ProtocolResolver.class)
static class S3AutoConfiguration {

@Bean
S3Client s3Client() {
return S3Client.builder()
.credentialsProvider(
() -> AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey()))
.region(Region.of(localstack.getRegion()))
.endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3)).build();
}

@Bean
S3OutputStreamProvider inMemoryBufferingS3StreamProvider(S3Client s3Client,
Optional<S3ObjectContentTypeResolver> contentTypeResolver) {
return new InMemoryBufferingS3OutputStreamProvider(s3Client,
contentTypeResolver.orElseGet(PropertiesS3ObjectContentTypeResolver::new));
}

}

}