GoodforGod / arangodb-testcontainers

⚙️ TestContainers ArangoDB module implementation.
https://testcontainers.com/modules/arangodb/
MIT License
12 stars 1 forks source link
arangodb arangodb-container arangodb-testcontainer testcontainers testcontainers-arango testcontainers-arangodb

ArangoDB TestContainers

Minimum required Java version Maven Central Java CI Quality Gate Status Coverage Maintainability Rating

This is ArangoDB TestContainers module for running database as Docker container.

Features:

Dependency :rocket:

Gradle

testImplementation "com.github.goodforgod:arangodb-testcontainer:3.0.1"

Maven

<dependency>
    <groupId>com.github.goodforgod</groupId>
    <artifactId>arangodb-testcontainer</artifactId>
    <version>3.0.1</version>
    <scope>test</scope>
</dependency>

Usage

Check this TestContainers tutorials for Jupiter / JUnit 5 examples.

Run ArangoDB container without authentication.

@Testcontainers
class ArangoContainerTests {

    @Container
    private static final ArangoContainer<?> container = new ArangoContainer<>("arangodb:3.11.2")
            .withoutAuth();

    @Test
    void checkContainerIsRunning() {
        assertTrue(container.isRunning());
    }
}

Run ArangoDB Cluster without authentication.

@Testcontainers
class ArangoContainerTests {

    @Container
    private static final ArangoCluster CLUSTER = ArangoCluster.builder("arangodb:3.11.2")
            .withoutAuth()
            .build();

    @Test
    void checkContainerIsRunning() {
        assertTrue(CLUSTER.getAgentLeader().isRunning());
    }
}

Container

Up & Running

Container implements startup strategy and will be available to TestContainer framework automatically when database will be ready for accepting connections.

Check here for more info about strategies.

Auth

All authentication options are available as per ArangoDB Docker description.

Without authentication or password or random password configuration is required as per docker image.

Without Authentication

You can run ArangoDB without authentication by specifying with setter.

@Testcontainers
class ArangoContainerTests {

    @Container
    private static final ArangoContainer<?> container = new ArangoContainer<>()
            .withoutAuth();

    @Test
    void checkContainerIsRunning() {
        assertTrue(container.isRunning());
    }
}

With Password

Database default user is root. You can specify desired password that will be assigned to root user.

@Testcontainers
class ArangoContainerTests {

    @Container
    private static final ArangoContainer<?> container = new ArangoContainer<>()
            .withPassword("mypass");

    @Test
    void checkContainerIsRunning() {
        assertTrue(container.isRunning());
    }
}

With Random Password

You can run container with random password for root user, but is such case, there is no methods to retrieve that password. You will have to retrieve it somehow by your own.

@Testcontainers
class ArangoContainerTests {

    @Container
    private static final ArangoContainer<?> container = new ArangoContainer<>()
            .withRandomPassword();

    @Test
    void checkContainerIsRunning() {
        assertTrue(container.isRunning());
    }
}

Cluster

You can run ArangoDB cluster as TestContainers.

Default cluster with 3 Agent nodes, 2 DBServer nodes and 2 Coordinator nodes is preconfigured for easy usage.

@Testcontainers
class ArangoContainerTests {

    @Container
    private static final ArangoCluster CLUSTER = ArangoCluster.builder("arangodb:3.11.2")
            .withPassword("mypass")
            .build();

    @Test
    void checkContainerIsRunning() {
        CLUSTER.getHost();
        CLUSTER.getPort();
        CLUSTER.getUser();
        CLUSTER.getPassword();
    }
}

Cluster Builder

You can build cluster with desired size via ArangoClusterBuilder.

You can check each container type via specified cluster container method.

final ArangoCluster cluster = ArangoCluster.builder("arangodb:3.11.2")
            .withAgentNodes(3)              // 3 agent nodes by default
            .withDatabaseNodes(2)           // 2 dbserver nodes by default
            .withCoordinatorNodes(2)        // 2 coordinator nodes by default
            .build();

License

This project licensed under the MIT - see the LICENSE file for details.