Skip to content

Instantly share code, notes, and snippets.

@eddumelendez
Last active May 31, 2022 21:26
Show Gist options
  • Save eddumelendez/18da7801d2b601ddb5ddf1a47508bade to your computer and use it in GitHub Desktop.
Save eddumelendez/18da7801d2b601ddb5ddf1a47508bade to your computer and use it in GitHub Desktop.
Testcontainers and localstack
#!/bin/sh
awslocal s3api create-bucket --bucket s3-demo
echo "s3 bucket created."
@Testcontainers
class LocalstackTest {
@Container
private final LocalStackContainer localstack =
new LocalStackContainer(DockerImageName.parse("localstack/localstack").withTag("0.14.2"))
.withCopyFileToContainer(MountableFile.forClasspathResource("/localstack"), "/docker-entrypoint-initaws.d")
.withServices(Service.S3)
.waitingFor(Wait.forLogMessage(".*s3 bucket created\\.\n", 1));
@Test
void test() throws IOException, InterruptedException {
ExecResult execResult = this.localstack.execInContainer("awslocal", "s3api", "list-buckets");
assertThat(execResult.getStdout()).contains("s3-demo");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment