A Testcontainers implementation for NODE-RED.
The @Container
annotation used here in the readme is from the JUnit 5 support of Testcontainers.
Please refer to the Testcontainers documentation for more information.
Simply spin up a default NODE-RED instance:
@Container
static final NodeRedContainer nodeRedContainer = new NodeRedContainer();
Use another NODE-RED Docker image/version than used in this Testcontainers:
@Container
static final NodeRedContainer nodeRedContainer = new NodeRedContainer("nodered/node-red:2.1.0");
Power up a NODE-RED instance with existing flows.json
and flows_cred.json
file (from classpath):
@Container
static final NodeRedContainer nodeRedContainer = new NodeRedContainer()
.withFlowsJson("flows_jsonplaceholder_posts.json")
.withFlowsCredJson("flows_cred.json")
.withSettings(Settings
.builder()
.credentialSecret(MY_NODE_RED_CREDENTIAL_SECRET)
.build());
Power up a NODE-RED instance with a flows.json
witch need a external 3rd party library modules have been installed at boostrapping instant. Even, you can combine NODE-RED container with other containers wich are also power up with Testcontainers
@Container
static final MariaDBContainer mariaDbContainer =
new MariaDBContainer(DockerImageName.parse("mariadb"))
.withPassword("my_cool_secret")
.withNetwork(network)
.withCreateContainerCmdModifier(cmd -> {
cmd.withName(MARIA_DB_CONTAINER_NAME);
});
@Container
static final NodeRedContainer nodeRedContainer =
new NodeRedContainer()
.withThirdPartyLibraryNodesDependencies(
ThirdPartyLibraryNodesDependency
.builder()
.module("node-red-node-mysql")
.version("1.0.1")
.build()
)
.withSettings(Settings
.builder()
.externalModules(Settings.ExternalModules
.builder()
.autoInstall(true)
.build())
.credentialSecret(MY_NODE_RED_CREDENTIAL_SECRET)
.disableEditor(true)
.build())
.withFlowsJson("mariadb/flows.json")
.withFlowsCredJson("mariadb/flows_cred.json")
.withNetwork(network);
Finally, you can obtain several properties from the NODE-RED container:
String endpoint = nodeRedContainer.getNodeRedUrl();
See also NodeRedContainerTest
and NodeRedContainerThirdPartyLibraryNodesDependenciesTest
classes and the other integration tests.
The release versions of this project are available at Maven Central.
Simply put the dependency coordinates to your pom.xml
(or something similar, if you use e.g. Gradle or something else):
<dependency>
<groupId>io.github.jsoladur</groupId>
<artifactId>node-red-testcontainers</artifactId>
<version>${node-red-testcontainers.version}</version>
<scope>test</scope>
</dependency>
MIT License
Copyright (c) 2022 José María Sola Durán
See LICENSE file for details.
Many thanks to the creators and maintainers of NODE-RED. You do an awesome job!
Thanks a lot to @dasniko for some inspiration for this project.