-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Azurite TestContainer for Azure blob testing (#549)
* Azurite TestContainer for Azure blob testing * Add testconteiners for AWS, fix broken multi-tenant test
- Loading branch information
Showing
7 changed files
with
181 additions
and
40 deletions.
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
...nt-azure-storage/src/test/java/internal/org/springframework/content/azure/it/Azurite.java
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,57 @@ | ||
package internal.org.springframework.content.azure.it; | ||
|
||
import java.io.Serializable; | ||
|
||
import com.azure.storage.blob.BlobServiceClientBuilder; | ||
import org.testcontainers.containers.GenericContainer; | ||
|
||
/** | ||
* This class provides a TestContainers implementation of Azure storage via | ||
* an Azurite docker container. | ||
* | ||
* Please refer to the following for details:- | ||
* <a href="https://www.testcontainers.org">http://www.testcontainers.org</a> | ||
* <a href="http://github.com/testcontainers/testcontainers-java">http://github.com/testcontainers/testcontainers-java</a> | ||
* <a href="http://github.com/Azure/Azurite">http://github.com/Azure/Azurite</a> | ||
*/ | ||
|
||
public class Azurite extends GenericContainer<Azurite> implements Serializable { | ||
|
||
// Will default to latest tag on every test run | ||
private static final String DOCKER_IMAGE_NAME = "mcr.microsoft.com/azure-storage/azurite"; | ||
|
||
// Default config as per Azurite docs | ||
private static final int BLOB_SERVICE_PORT = 10000; | ||
|
||
@SuppressWarnings("HttpUrlsUsage") // Testing only | ||
private static final String ENDPOINT = "http://%s:%d/%s"; | ||
private static final String DEV_ACC_NAME = "devstoreaccount1"; | ||
private static final String PROTOCOL = "DefaultEndpointsProtocol=http"; | ||
private static final String ACC_NAME = "AccountName=" + DEV_ACC_NAME; | ||
private static final String ACC_KEY = | ||
"AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; | ||
|
||
private Azurite() { | ||
super(DOCKER_IMAGE_NAME); | ||
this.start(); | ||
} | ||
|
||
public static BlobServiceClientBuilder getBlobServiceClientBuilder() { | ||
final String host = Singleton.INSTANCE.getContainerIpAddress(); | ||
final Integer mappedPort = Singleton.INSTANCE.getMappedPort(BLOB_SERVICE_PORT); | ||
final String endpoint = String.format(ENDPOINT, host, mappedPort, DEV_ACC_NAME); | ||
|
||
return new BlobServiceClientBuilder() | ||
.endpoint(endpoint) | ||
.connectionString(String.join(";", PROTOCOL, ACC_NAME, ACC_KEY, "BlobEndpoint=" + endpoint)); | ||
} | ||
|
||
@SuppressWarnings("unused") // Serializable safe singleton usage | ||
protected Azurite readResolve() { | ||
return Singleton.INSTANCE; | ||
} | ||
|
||
private static class Singleton { | ||
private static final Azurite INSTANCE = new Azurite(); | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
spring-content-s3/src/test/java/internal/org/springframework/content/s3/it/LocalStack.java
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,51 @@ | ||
package internal.org.springframework.content.s3.it; | ||
|
||
import java.io.Serializable; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import org.apache.http.client.utils.URIBuilder; | ||
import org.testcontainers.containers.localstack.LocalStackContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
public class LocalStack extends LocalStackContainer implements Serializable { | ||
|
||
private static final DockerImageName IMAGE_NAME = DockerImageName.parse("localstack/localstack"); | ||
|
||
private LocalStack() { | ||
super(IMAGE_NAME); | ||
withServices(Service.S3); | ||
start(); | ||
} | ||
|
||
private static class Singleton { | ||
private static final LocalStack INSTANCE = new LocalStack(); | ||
} | ||
|
||
public static AmazonS3 getAmazonS3Client() { | ||
return AmazonS3ClientBuilder | ||
.standard() | ||
.withEndpointConfiguration(Singleton.INSTANCE.getEndpointConfiguration(Service.S3)) | ||
.withCredentials(Singleton.INSTANCE.getDefaultCredentialsProvider()) | ||
.withPathStyleAccessEnabled(true) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public URI getEndpointOverride(EnabledService service) { | ||
try { | ||
// super method converts localhost to 127.0.0.1 which fails on macos | ||
// need to revert it back to whatever getContainerIpAddress() returns | ||
return new URIBuilder(super.getEndpointOverride(service)).setHost(getContainerIpAddress()).build(); | ||
} catch (URISyntaxException e) { | ||
throw new IllegalStateException("Cannot obtain endpoint URL", e); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") // Serializable safe singleton usage | ||
protected LocalStack readResolve() { | ||
return Singleton.INSTANCE; | ||
} | ||
} |
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