1
1
package org .testcontainers .containers .localstack ;
2
2
3
3
4
+ import com .amazonaws .services .logs .AWSLogs ;
5
+ import com .amazonaws .services .logs .AWSLogsClientBuilder ;
6
+ import com .amazonaws .services .logs .model .CreateLogGroupRequest ;
7
+ import com .amazonaws .services .logs .model .CreateLogGroupResult ;
8
+ import com .amazonaws .services .logs .model .DescribeLogGroupsRequest ;
9
+ import com .amazonaws .services .logs .model .LogGroup ;
4
10
import com .amazonaws .services .s3 .AmazonS3 ;
5
11
import com .amazonaws .services .s3 .AmazonS3ClientBuilder ;
6
12
import com .amazonaws .services .s3 .model .Bucket ;
13
19
import org .apache .commons .io .IOUtils ;
14
20
import org .junit .Assert ;
15
21
import org .junit .ClassRule ;
22
+ import org .junit .Ignore ;
16
23
import org .junit .Test ;
17
24
import org .junit .experimental .runners .Enclosed ;
18
25
import org .junit .runner .RunWith ;
31
38
import static org .rnorth .visibleassertions .VisibleAssertions .assertTrue ;
32
39
import static org .testcontainers .containers .localstack .LocalStackContainer .Service .S3 ;
33
40
import static org .testcontainers .containers .localstack .LocalStackContainer .Service .SQS ;
41
+ import static org .testcontainers .containers .localstack .LocalStackContainer .Service .CLOUDWATCHLOGS ;
34
42
35
43
/**
36
44
* Tests for Localstack Container, used both in bridge network (exposed to host) and docker network modes.
@@ -48,7 +56,7 @@ public static class WithoutNetwork {
48
56
// without_network {
49
57
@ ClassRule
50
58
public static LocalStackContainer localstack = new LocalStackContainer ()
51
- .withServices (S3 , SQS );
59
+ .withServices (S3 , SQS , CLOUDWATCHLOGS );
52
60
// }
53
61
54
62
@ Test
@@ -95,6 +103,20 @@ public void sqsTestOverBridgeNetwork() {
95
103
.count ();
96
104
assertEquals ("the sent message can be received" , 1L , messageCount );
97
105
}
106
+
107
+ @ Test
108
+ @ Ignore ("Fails due to https://github.com/localstack/localstack/issues/1434" )
109
+ public void cloudWatchLogsTestOverBridgeNetwork () {
110
+ AWSLogs logs = AWSLogsClientBuilder .standard ()
111
+ .withEndpointConfiguration (localstack .getEndpointConfiguration (CLOUDWATCHLOGS ))
112
+ .withCredentials (localstack .getDefaultCredentialsProvider ()).build ();
113
+
114
+ logs .createLogGroup (new CreateLogGroupRequest ("foo" ));
115
+
116
+ List <LogGroup > groups = logs .describeLogGroups ().getLogGroups ();
117
+ assertEquals ("One log group should be created" , 1 , groups .size ());
118
+ assertEquals ("Name of created log group is [foo]" , "foo" , groups .get (0 ).getLogGroupName ());
119
+ }
98
120
}
99
121
100
122
public static class WithNetwork {
@@ -105,7 +127,7 @@ public static class WithNetwork {
105
127
public static LocalStackContainer localstackInDockerNetwork = new LocalStackContainer ()
106
128
.withNetwork (network )
107
129
.withNetworkAliases ("notthis" , "localstack" ) // the last alias is used for HOSTNAME_EXTERNAL
108
- .withServices (S3 , SQS );
130
+ .withServices (S3 , SQS , CLOUDWATCHLOGS );
109
131
// }
110
132
111
133
@ ClassRule
@@ -139,6 +161,11 @@ public void sqsTestOverDockerNetwork() throws Exception {
139
161
assertTrue ("the sent message can be received" , message .contains ("\" Body\" : \" test\" " ));
140
162
}
141
163
164
+ @ Test
165
+ public void cloudWatchLogsTestOverDockerNetwork () throws Exception {
166
+ runAwsCliAgainstDockerNetworkContainer ("logs create-log-group --log-group-name foo" , CLOUDWATCHLOGS .getPort ());
167
+ }
168
+
142
169
private String runAwsCliAgainstDockerNetworkContainer (String command , final int port ) throws Exception {
143
170
final String [] commandParts = String .format ("/usr/bin/aws --region eu-west-1 %s --endpoint-url http://localstack:%d --no-verify-ssl" , command , port ).split (" " );
144
171
final Container .ExecResult execResult = awsCliInDockerNetwork .execInContainer (commandParts );
0 commit comments