Gizmo :: K8s

End-to-end testing with JUnit and Docker

License

License

GroupId

GroupId

org.opennms.gizmo
ArtifactId

ArtifactId

gizmo-k8s
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

bundle
Description

Description

Gizmo :: K8s
End-to-end testing with JUnit and Docker

Download gizmo-k8s

Dependencies

compile (6)

Group / Artifact Type Version
org.opennms.gizmo : gizmo-api jar 1.0.0
io.fabric8 : kubernetes-client jar 2.2.13
io.fabric8 : kubernetes-api jar 2.2.209
com.hubspot.jinjava : jinjava jar 2.1.16
org.apache.commons : commons-exec jar 1.3
org.yaml : snakeyaml jar 1.18

test (2)

Group / Artifact Type Version
org.apache.logging.log4j : log4j-slf4j-impl jar 2.8.2
org.apache.logging.log4j : log4j-core jar 2.8.2

Project Modules

There are no modules declared in this project.

Gizmo

End-to-end testing with JUnit and Docker.

Getting Started

Add gizmo to your Maven dependencies:

<dependency>
    <groupId>org.opennms.gizmo</groupId>
    <artifactId>gizmo-docker</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

Use JUnit rules to configure one or more stacks:

@Rule
public GizmoDockerRule gizmo = GizmoDockerRule.builder()
    .withContainer(NGINX_ALIAS, (stacker) -> {
       return ContainerConfig.builder()
               .image("nginx:1.11.1-alpine")
               .hostConfig(HostConfig.builder()
                .publishAllPorts(true)
                .build())
               .build();
    })
    .withWaitingRule((stacker) -> {
        // When the container ports are bound to random host ports
        // you can use this call to determine the effective address of the service
        final InetSocketAddress httpAddr = stacker.getServiceAddress(NGINX_ALIAS, 80);
        await().atMost(2, MINUTES).pollInterval(5, SECONDS).pollDelay(0, SECONDS)
            .until(() -> HttpUtils.get(httpAddr, "/") != null);
    }).build();

Reference the services hosted by the stacks in your tests:

@Test
public void canSpawnContainerAndDoGet() throws IOException {
    // At this point, our container should is up and running and ready to answer requests
    final GizmoDockerStacker stacker = gizmo.getStacker();
    final InetSocketAddress httpAddr = stacker.getServiceAddress(NGINX_ALIAS, 80);
    assertThat(HttpUtils.get(httpAddr, "/"), containsString("Welcome to nginx!"));
}

Take a look at the integration tests for more examples.

org.opennms.gizmo

OpenNMS

Enterprise-Grade Open-Source Network Management

Versions

Version
1.0.0