Skip to content

Commit

Permalink
Use testcontainers for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bnayfeh committed Nov 6, 2024
1 parent 9cf096b commit eb10535
Show file tree
Hide file tree
Showing 4 changed files with 2,555 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static class Builder {

/**
* @param baseUrl base URL of the SearXNG instance e.g. http://localhost:8080
* @return {@link Builder}
*/
public Builder baseUrl(String baseUrl) {
this.baseUrl = baseUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
package dev.langchain4j.community.web.search.searxng;

import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import dev.langchain4j.web.search.WebSearchEngine;
import dev.langchain4j.web.search.WebSearchEngineIT;

@EnabledIfEnvironmentVariable(named = "SEARXNG_BASE_URL", matches = ".+")
@Testcontainers
class SearXNGWebSearchEngineIT extends WebSearchEngineIT {

WebSearchEngine webSearchEngine = SearXNGWebSearchEngine.builder().baseUrl(System.getenv("SEARXNG_BASE_URL")).build();

@SuppressWarnings("resource")
@Container
static GenericContainer<?> searxng = new GenericContainer<>(DockerImageName.parse("searxng/searxng:latest"))
.withExposedPorts(8080)
.withCopyFileToContainer(MountableFile.forClasspathResource("settings.yml"), "/usr/local/searxng/searx/settings.yml")
.waitingFor(Wait.forLogMessage(".*spawned uWSGI worker.*\\n", 1));

@Override
protected WebSearchEngine searchEngine() {
return webSearchEngine;
return SearXNGWebSearchEngine.builder().baseUrl("http://" + searxng.getHost() + ":" + searxng.getMappedPort(8080)).build();
}

@BeforeAll
static void startContainers() {
searxng.start();
}

@AfterAll
static void stopContainers() {
searxng.stop();
searxng.close();
}
}
Loading

0 comments on commit eb10535

Please sign in to comment.