Skip to content
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
1 change: 1 addition & 0 deletions modules/localstack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dependencies {
compileOnly 'com.amazonaws:aws-java-sdk-s3:1.11.683'
testCompile 'com.amazonaws:aws-java-sdk-s3:1.11.683'
testCompile 'com.amazonaws:aws-java-sdk-sqs:1.11.636'
testCompile 'com.amazonaws:aws-java-sdk-logs:1.11.636'
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public enum Service {
SSM("ssm", 4583),
SECRETSMANAGER("secretsmanager", 4584),
STEPFUNCTIONS("stepfunctions", 4585),
CLOUDWATCHLOGS("cloudwatchlogs", 4586),
CLOUDWATCHLOGS("logs", 4586),
STS("sts", 4592),
IAM("iam", 4593);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package org.testcontainers.containers.localstack;


import com.amazonaws.services.logs.AWSLogs;
import com.amazonaws.services.logs.AWSLogsClientBuilder;
import com.amazonaws.services.logs.model.CreateLogGroupRequest;
import com.amazonaws.services.logs.model.CreateLogGroupResult;
import com.amazonaws.services.logs.model.DescribeLogGroupsRequest;
import com.amazonaws.services.logs.model.LogGroup;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.Bucket;
Expand All @@ -13,6 +19,7 @@
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
Expand All @@ -31,6 +38,7 @@
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.S3;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SQS;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.CLOUDWATCHLOGS;

/**
* Tests for Localstack Container, used both in bridge network (exposed to host) and docker network modes.
Expand All @@ -48,7 +56,7 @@ public static class WithoutNetwork {
// without_network {
@ClassRule
public static LocalStackContainer localstack = new LocalStackContainer()
.withServices(S3, SQS);
.withServices(S3, SQS, CLOUDWATCHLOGS);
// }

@Test
Expand Down Expand Up @@ -95,6 +103,20 @@ public void sqsTestOverBridgeNetwork() {
.count();
assertEquals("the sent message can be received", 1L, messageCount);
}

@Test
@Ignore("Fails due to https://github.com/localstack/localstack/issues/1434")
public void cloudWatchLogsTestOverBridgeNetwork() {
AWSLogs logs = AWSLogsClientBuilder.standard()
.withEndpointConfiguration(localstack.getEndpointConfiguration(CLOUDWATCHLOGS))
.withCredentials(localstack.getDefaultCredentialsProvider()).build();

logs.createLogGroup(new CreateLogGroupRequest("foo"));

List<LogGroup> groups = logs.describeLogGroups().getLogGroups();
assertEquals("One log group should be created", 1, groups.size());
assertEquals("Name of created log group is [foo]", "foo", groups.get(0).getLogGroupName());
}
}

public static class WithNetwork {
Expand All @@ -105,7 +127,7 @@ public static class WithNetwork {
public static LocalStackContainer localstackInDockerNetwork = new LocalStackContainer()
.withNetwork(network)
.withNetworkAliases("notthis", "localstack") // the last alias is used for HOSTNAME_EXTERNAL
.withServices(S3, SQS);
.withServices(S3, SQS, CLOUDWATCHLOGS);
// }

@ClassRule
Expand Down Expand Up @@ -139,6 +161,11 @@ public void sqsTestOverDockerNetwork() throws Exception {
assertTrue("the sent message can be received", message.contains("\"Body\": \"test\""));
}

@Test
public void cloudWatchLogsTestOverDockerNetwork() throws Exception {
runAwsCliAgainstDockerNetworkContainer("logs create-log-group --log-group-name foo", CLOUDWATCHLOGS.getPort());
}

private String runAwsCliAgainstDockerNetworkContainer(String command, final int port) throws Exception {
final String[] commandParts = String.format("/usr/bin/aws --region eu-west-1 %s --endpoint-url http://localstack:%d --no-verify-ssl", command, port).split(" ");
final Container.ExecResult execResult = awsCliInDockerNetwork.execInContainer(commandParts);
Expand Down