-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
160 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ body: | |
- MySQL | ||
- Neo4j | ||
- NGINX | ||
- OpenFGA | ||
- Oracle Free | ||
- Oracle XE | ||
- OrientDB | ||
|
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 |
---|---|---|
|
@@ -41,6 +41,7 @@ body: | |
- MySQL | ||
- Neo4j | ||
- NGINX | ||
- OpenFGA | ||
- Oracle Free | ||
- Oracle XE | ||
- OrientDB | ||
|
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 |
---|---|---|
|
@@ -41,6 +41,7 @@ body: | |
- MySQL | ||
- Neo4j | ||
- NGINX | ||
- OpenFGA | ||
- Oracle Free | ||
- Oracle XE | ||
- OrientDB | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# OpenFGA | ||
|
||
Testcontainers module for [OpenFGA](https://hub.docker.com/r/"openfga/openfga). | ||
|
||
## OpenFGAContainer's usage examples | ||
|
||
You can start an OpenFGA container instance from any Java application by using: | ||
|
||
<!--codeinclude--> | ||
[OpenFGA container](../../modules/openfga/src/test/java/org/testcontainers/openfga/OpenFGAContainerTest.java) inside_block:container | ||
<!--/codeinclude--> | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Add the following dependency to your `pom.xml`/`build.gradle` file: | ||
|
||
=== "Gradle" | ||
```groovy | ||
testImplementation "org.testcontainers:openfga:{{latest_version}}" | ||
``` | ||
|
||
=== "Maven" | ||
```xml | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>openfga</artifactId> | ||
<version>{{latest_version}}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
description = "Testcontainers :: OpenFGA" | ||
|
||
dependencies { | ||
api project(':testcontainers') | ||
|
||
testImplementation 'org.assertj:assertj-core:3.25.1' | ||
testImplementation 'dev.openfga:openfga-sdk:0.3.2' | ||
} | ||
|
||
test { | ||
javaLauncher = javaToolchains.launcherFor { | ||
languageVersion = JavaLanguageVersion.of(11) | ||
} | ||
} | ||
|
||
compileTestJava { | ||
javaCompiler = javaToolchains.compilerFor { | ||
languageVersion = JavaLanguageVersion.of(11) | ||
} | ||
options.release.set(11) | ||
} |
45 changes: 45 additions & 0 deletions
45
modules/openfga/src/main/java/org/testcontainers/openfga/OpenFGAContainer.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.testcontainers.openfga; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
/** | ||
* Testcontainers implementation for OpenFGA. | ||
* <p> | ||
* Supported image: {@code openfga/openfga} | ||
* <p> | ||
* Exposed ports: | ||
* <ul> | ||
* <li>Playground: 3000</li> | ||
* <li>HTTP: 8080</li> | ||
* <li>gRPC: 8081</li> | ||
* </ul> | ||
*/ | ||
public class OpenFGAContainer extends GenericContainer<OpenFGAContainer> { | ||
|
||
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("openfga/openfga"); | ||
|
||
public OpenFGAContainer(String image) { | ||
this(DockerImageName.parse(image)); | ||
} | ||
|
||
public OpenFGAContainer(DockerImageName dockerImageName) { | ||
super(dockerImageName); | ||
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
|
||
withExposedPorts(3000, 8080, 8081); | ||
withCommand("run"); | ||
waitingFor( | ||
Wait.forHttp("/healthz").forPort(8080).forResponsePredicate(response -> response.contains("SERVING")) | ||
); | ||
} | ||
|
||
public String getHttpEndpoint() { | ||
return "http://" + getHost() + ":" + getMappedPort(8080); | ||
} | ||
|
||
public String getGrpcEndpoint() { | ||
return "http://" + getHost() + ":" + getMappedPort(8081); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
modules/openfga/src/test/java/org/testcontainers/openfga/OpenFGAContainerTest.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.testcontainers.openfga; | ||
|
||
import dev.openfga.sdk.api.client.OpenFgaClient; | ||
import dev.openfga.sdk.api.client.model.ClientCreateStoreResponse; | ||
import dev.openfga.sdk.api.configuration.ClientConfiguration; | ||
import dev.openfga.sdk.api.model.CreateStoreRequest; | ||
import dev.openfga.sdk.errors.FgaInvalidParameterException; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class OpenFGAContainerTest { | ||
|
||
@Test | ||
public void withDefaultConfig() throws FgaInvalidParameterException, ExecutionException, InterruptedException { | ||
try ( // container | ||
OpenFGAContainer openfga = new OpenFGAContainer("openfga/openfga:v1.4.3") | ||
// } | ||
) { | ||
openfga.start(); | ||
|
||
ClientConfiguration config = new ClientConfiguration().apiUrl(openfga.getHttpEndpoint()); | ||
OpenFgaClient client = new OpenFgaClient(config); | ||
|
||
assertThat(client.listStores().get().getStores()).isEmpty(); | ||
ClientCreateStoreResponse store = client.createStore(new CreateStoreRequest().name("test")).get(); | ||
assertThat(store.getId()).isNotNull(); | ||
assertThat(client.listStores().get().getStores()).hasSize(1); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
<logger name="org.testcontainers" level="INFO"/> | ||
</configuration> |