-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(itest): updated the tests and created a localstack resource (#160)
Co-authored-by: Andrew Azores <[email protected]>
- Loading branch information
1 parent
c4f8511
commit 829584d
Showing
12 changed files
with
291 additions
and
219 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
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
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
93 changes: 93 additions & 0 deletions
93
src/test/java/io/cryostat/resources/LocalStackResource.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,93 @@ | ||
/* | ||
* Copyright The Cryostat Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.cryostat.resources; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.test.common.DevServicesContext; | ||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
import org.jboss.logging.Logger; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
public class LocalStackResource | ||
implements QuarkusTestResourceLifecycleManager, DevServicesContext.ContextAware { | ||
|
||
private static int S3_PORT = 4566; | ||
private static final String IMAGE_NAME = "docker.io/localstack/localstack:latest"; | ||
private static final Map<String, String> envMap = | ||
Map.of( | ||
"START_WEB", "0", | ||
"SERVICES", "s3", | ||
"EAGER_SERVICE_LOADING", "1", | ||
"SKIP_SSL_CERT_DOWNLOAD", "1", | ||
"DISABLE_EVENTS", "1"); | ||
private static final Logger logger = Logger.getLogger(LocalStackResource.class); | ||
private Optional<String> containerNetworkId; | ||
private GenericContainer<?> container; | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
container = | ||
new GenericContainer<>(DockerImageName.parse(IMAGE_NAME)) | ||
.withExposedPorts(S3_PORT) | ||
.withEnv(envMap) | ||
.waitingFor(Wait.forHealthcheck()); | ||
containerNetworkId.ifPresent(container::withNetworkMode); | ||
|
||
container.start(); | ||
|
||
String networkHostPort = | ||
"http://" + container.getHost() + ":" + container.getMappedPort(S3_PORT); | ||
|
||
Map<String, String> properties = new HashMap<String, String>(); | ||
properties.put("quarkus.s3.aws.region", "us-east-1"); | ||
properties.put("s3.url.override", networkHostPort); | ||
properties.put("quarkus.s3.endpoint-override", properties.get("s3.url.override")); | ||
properties.put("quarkus.s3.path-style-access", "true"); | ||
properties.put("quarkus.s3.aws.credentials.type", "static"); | ||
properties.put("quarkus.s3.aws.credentials.static-provider.access-key-id", "unused"); | ||
properties.put("quarkus.s3.aws.credentials.static-provider.secret-access-key", "unused"); | ||
properties.put( | ||
"aws.access-key-id", | ||
properties.get("quarkus.s3.aws.credentials.static-provider.access-key-id")); | ||
properties.put("aws.accessKeyId", properties.get("aws.access-key-id")); | ||
properties.put( | ||
"aws.secret-access-key", | ||
properties.get("quarkus.s3.aws.credentials.static-provider.secret-access-key")); | ||
properties.put("aws.secretAccessKey", properties.get("aws.secret-access-key")); | ||
properties.entrySet().forEach(e -> System.setProperty(e.getKey(), e.getValue())); | ||
logger.infov("Configured properties: {0}", properties); | ||
|
||
return properties; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
if (container != null) { | ||
container.stop(); | ||
container.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public void setIntegrationTestContext(DevServicesContext context) { | ||
containerNetworkId = context.containerNetworkId(); | ||
} | ||
} |
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
Oops, something went wrong.