Skip to content

Commit

Permalink
[Localstack] Get region from env variables or default (#3556)
Browse files Browse the repository at this point in the history
Co-authored-by: Pozueco Adrian <pozuecoa@ryanair.com>
Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com>
  • Loading branch information
3 people committed Jun 2, 2022
1 parent 5d3349f commit 6985636
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -45,6 +45,8 @@ public class LocalStackContainer extends GenericContainer<LocalStackContainer> {

private static final String DEFAULT_TAG = "0.11.2";

private static final String DEFAULT_REGION = "us-east-1";

@Deprecated
public static final String VERSION = DEFAULT_TAG;

Expand Down Expand Up @@ -311,7 +313,7 @@ public String getSecretKey() {
* @return a default region
*/
public String getRegion() {
return "us-east-1";
return this.getEnvMap().getOrDefault("DEFAULT_REGION", DEFAULT_REGION);
}

public interface EnabledService {
Expand Down
@@ -1,5 +1,6 @@
package org.testcontainers.containers.localstack;

import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.kms.AWSKMS;
import com.amazonaws.services.kms.AWSKMSClientBuilder;
import com.amazonaws.services.kms.model.CreateKeyRequest;
Expand Down Expand Up @@ -286,4 +287,29 @@ private String runAwsCliAgainstDockerNetworkContainer(String command) throws Exc
return logs;
}
}

public static class WithRegion {

// with_region {
private static String region = "eu-west-1";

@ClassRule
public static LocalStackContainer localstack = new LocalStackContainer(LocalstackTestImages.LOCALSTACK_IMAGE)
.withEnv("DEFAULT_REGION", region)
.withServices(Service.S3);

// }

@Test
public void s3EndpointHasProperRegion() {
final AwsClientBuilder.EndpointConfiguration endpointConfiguration = localstack.getEndpointConfiguration(
Service.S3
);
assertEquals(
"The endpoint configuration has right region",
region,
endpointConfiguration.getSigningRegion()
);
}
}
}

0 comments on commit 6985636

Please sign in to comment.