Skip to content

Commit

Permalink
Release 1.0.4.
Browse files Browse the repository at this point in the history
Changelog:
- Allow to override standalone warp10 configuration in the container.
  • Loading branch information
judu committed Sep 21, 2021
1 parent dd0491f commit c854605
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<url>https://github.com/CleverCloud/testcontainers-warp10</url>
<groupId>com.clever-cloud</groupId>
<artifactId>testcontainers-warp10</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,32 @@ public Warp10Container(final String tag) {
this(DEFAULT_IMAGE_NAME.withTag(tag));
}


/**
* Instantiate warp10 container with server-side macros.
*
* @param tag version tag for the docker image.
* @param tag version tag for the docker image.
* @param macrosFolder File pointing at the macros folder you want to install.
* This should be a full "macros folder" as defined in warp10's doc:
* the macros **must** be placed into subfolders.
*/
public Warp10Container(final String tag, final File macrosFolder) {
super(new ImageFromDockerfile()
.withFileFromFile(macrosFolder.getPath(), macrosFolder)
.withDockerfileFromBuilder(builder -> builder
.from(DEFAULT_IMAGE_NAME.withTag(tag).asCanonicalNameString())
.add(macrosFolder.getPath(), "/opt/warp10/macros/")
.build()
)
);
this(tag, macrosFolder, null);
}

/**
* Instantiate warp10 container with server-side macros and config override.
*
* @param tag version tag for the docker image.
* @param macrosFolder File pointing at the macros folder you want to install.
* This should be a full "macros folder" as defined in warp10's doc:
* the macros **must** be placed into subfolders.
* @param configFolder File pointing at the configuration files you want to install.
* The files in this folder should look like XX-name.conf.template (e.g. 20-warpscript.conf.template).
* They will override the template configuration files in /opt/warp10/conf.templates/standalone
*/
public Warp10Container(final String tag, final File macrosFolder, final File configFolder) {
super(setupImage(tag, macrosFolder, configFolder));
this.init(DEFAULT_IMAGE_NAME.withTag(tag));
}

Expand All @@ -56,6 +65,33 @@ public Warp10Container(final DockerImageName dockerImageName) {
this.init(dockerImageName);
}

private static ImageFromDockerfile setupImage(final String tag, final File macrosFolder, final File configFolder) {
ImageFromDockerfile image = new ImageFromDockerfile();
if (macrosFolder != null) {
if (macrosFolder.exists()) {
image.withFileFromFile(macrosFolder.getPath(), macrosFolder);
} else {
throw new RuntimeException(String.format("Macro folder %s does not exist", macrosFolder.getPath()));
}
}
if (configFolder != null) {
if (configFolder.exists()) {
image.withFileFromFile(configFolder.getPath(), configFolder);
} else {
throw new RuntimeException(String.format("Config folder %s does not exist", configFolder.getPath()));
}
}
return image.withDockerfileFromBuilder(builder -> {
builder.from(DEFAULT_IMAGE_NAME.withTag(tag).asCanonicalNameString());
if (macrosFolder != null && macrosFolder.exists())
builder.add(macrosFolder.getPath(), "/opt/warp10/macros/");
if (configFolder != null && configFolder.exists())
builder.add(configFolder.getPath(), "/opt/warp10/conf.templates/standalone/");

builder.build();
});
}

private void init(final DockerImageName dockerImageName) {
logger().info("Starting a Warp10 container using [{}]", dockerImageName);
addExposedPort(WARP10_DEFAULT_PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Warp10ContainerTest {
private static final String Warp10GTS = "1// test{} 42";
private static final String Warp10MacroGTS = "1// test{} 42\n50// test{} 1337";
private static final String Warp10FetchMacroGTS = "[ '%s' 'test' {} 40 NOW 10 ] @me/test";
private static final String Warp10FetchMacroAndConfigGTS = "[ '%s' 'test' {} 40 NOW 10 ] @me/testlimit";
private static final String Warp10UpdateAPI = "/api/v0/update";
private static final String Warp10Version = "2.7.5";

Expand Down Expand Up @@ -63,6 +64,22 @@ public void warp10WithMacros() throws IOException {
}
}

@Test
public void warp10WithMacrosAndConfig() throws IOException {
try (Warp10Container container = new Warp10Container(Warp10Version, new File("src/test/resources/macros"), new File("src/test/resources/conf.d"))) {
container.start();

Response putGTS = warp10Request(container, Warp10UpdateAPI, Warp10MacroGTS, container.getWriteToken());
assertEquals(200, putGTS.code());

Response getGTS = warp10Request(container, Warp10FetchAPI, String.format(Warp10FetchMacroAndConfigGTS, container.getReadToken()), null);
System.out.println(getGTS.body().string());
assertEquals(200, getGTS.code());
assertNotNull(getGTS.header(Warp10FetchedHeader));
assertEquals(1, Integer.parseInt(getGTS.header(Warp10FetchedHeader)));
}
}

private Response warp10Request(Warp10Container container, String path, String body, String auth) throws IOException {
URL postGTS = new URL("http", container.getHTTPHost(), container.getHTTPPort(), path);

Expand Down
52 changes: 52 additions & 0 deletions src/test/resources/macros/me/testlimit.mc2
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<%
SAVE 'context' STORE

'list' STORE
NOW 'NOW' STORE

$list SIZE 6 ==
'Fetch_after can only have 6 parameters : read_token, class, labels, start, end, active_after'
ASSERTMSG

$list 0 GET 'rtoken' STORE
$list 1 GET 'class' STORE
$list 2 GET 'labels' STORE
$list 3 GET 'start_ts' STORE
$list 4 GET 'end_ts' STORE
$list 5 GET 'active_after_ts' STORE


<%
ISAUTHENTICATED NOT
%>
<%
$rtoken AUTHENTICATE
%>
IFT

1000000000 LIMIT

// Activity is taken account after at least 2 h
<% $active_after_ts $NOW 2 h - > %>
<%
{
'token' $rtoken
'labels' $labels
'class' $class
'start' $start_ts
'end' $end_ts
'active.after' $NOW 2 h -
} FETCH
%>
<%
{
'token' $rtoken
'active.after' $active_after_ts
'labels' $labels
'class' $class
'start' $start_ts
'end' $end_ts
} FETCH
%> IFTE
$context RESTORE
%>

0 comments on commit c854605

Please sign in to comment.