-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use testcontainers for integration tests
- Loading branch information
Showing
4 changed files
with
2,555 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 28 additions & 6 deletions
34
.../src/test/java/dev/langchain4j/community/web/search/searxng/SearXNGWebSearchEngineIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.