1
1
package dev .openfeature .contrib .providers .flagd .e2e ;
2
2
3
+ import org .apache .logging .log4j .util .Strings ;
3
4
import org .jetbrains .annotations .NotNull ;
4
5
import org .testcontainers .containers .GenericContainer ;
5
6
import org .testcontainers .containers .Network ;
6
7
import org .testcontainers .utility .DockerImageName ;
7
8
import org .testcontainers .utility .MountableFile ;
8
9
9
- import java .io .IOException ;
10
- import java .util .Properties ;
10
+ import java .io .File ;
11
+ import java .nio .file .Files ;
12
+ import java .util .List ;
11
13
12
14
public class ContainerConfig {
13
15
private static final String version ;
14
16
private static final Network network = Network .newNetwork ();
15
17
16
18
static {
17
- Properties properties = new Properties ();
19
+ String path = "test-harness/version.txt" ;
20
+ File file = new File (path );
18
21
try {
19
- properties . load ( Thread . currentThread (). getContextClassLoader (). getResourceAsStream ( "flagdTestbed.properties" ));
20
- version = properties . getProperty ( "version" );
21
- } catch (IOException e ) {
22
+ List < String > lines = Files . readAllLines ( file . toPath ( ));
23
+ version = lines . get ( 0 );
24
+ } catch (Exception e ) {
22
25
throw new RuntimeException (e );
23
26
}
24
27
}
25
28
29
+
26
30
/**
27
- *
28
31
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a stable sync flagd server with the port 9090 exposed
29
32
*/
30
- public static GenericContainer sync () {
33
+ public static GenericContainer sync () {
31
34
return sync (false , false );
32
35
}
33
36
34
37
/**
35
- *
36
- * @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
38
+ * @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
37
39
* @param addNetwork if set to true a custom network is attached for cross container access e.g. envoy --> sync:8015
38
40
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a sync flagd server with the port 8015 exposed
39
41
*/
40
42
public static GenericContainer sync (boolean unstable , boolean addNetwork ) {
41
- String container = generateContainerName ("flagd" , unstable );
43
+ String container = generateContainerName ("flagd" , unstable ? "unstable" : "" );
42
44
GenericContainer genericContainer = new GenericContainer (DockerImageName .parse (container ))
43
45
.withExposedPorts (8015 );
44
46
@@ -51,20 +53,18 @@ public static GenericContainer sync(boolean unstable, boolean addNetwork) {
51
53
}
52
54
53
55
/**
54
- *
55
56
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a stable flagd server with the port 8013 exposed
56
57
*/
57
58
public static GenericContainer flagd () {
58
59
return flagd (false );
59
60
}
60
61
61
62
/**
62
- *
63
63
* @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
64
64
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a flagd server with the port 8013 exposed
65
65
*/
66
66
public static GenericContainer flagd (boolean unstable ) {
67
- String container = generateContainerName ("flagd" , unstable );
67
+ String container = generateContainerName ("flagd" , unstable ? "unstable" : "" );
68
68
return new GenericContainer (DockerImageName .parse (container ))
69
69
.withExposedPorts (8013 );
70
70
}
@@ -73,7 +73,6 @@ public static GenericContainer flagd(boolean unstable) {
73
73
/**
74
74
* @return a {@link org.testcontainers.containers.GenericContainer} instance of envoy container using
75
75
* flagd sync service as backend expose on port 9211
76
- *
77
76
*/
78
77
public static GenericContainer envoy () {
79
78
final String container = "envoyproxy/envoy:v1.31.0" ;
@@ -85,14 +84,14 @@ public static GenericContainer envoy() {
85
84
.withNetworkAliases ("envoy" );
86
85
}
87
86
88
- private static @ NotNull String generateContainerName (String type , boolean unstable ) {
87
+ public static @ NotNull String generateContainerName (String type , String addition ) {
89
88
String container = "ghcr.io/open-feature/" ;
90
89
container += type ;
91
90
container += "-testbed" ;
92
- if (unstable ) {
93
- container += "-unstable" ;
91
+ if (! Strings . isBlank ( addition ) ) {
92
+ container += "-" + addition ;
94
93
}
95
- container += ":" + version ;
94
+ container += ":v " + version ;
96
95
return container ;
97
96
}
98
97
}
0 commit comments