2
2
3
3
import static io .restassured .RestAssured .when ;
4
4
5
- import com .fasterxml .jackson .databind .ObjectMapper ;
6
- import com .fasterxml .jackson .databind .ObjectReader ;
7
5
import dev .openfeature .contrib .providers .flagd .Config ;
8
6
import dev .openfeature .contrib .providers .flagd .FlagdProvider ;
9
7
import dev .openfeature .contrib .providers .flagd .e2e .FlagdContainer ;
21
19
import java .nio .file .Files ;
22
20
import java .nio .file .Path ;
23
21
import java .nio .file .Paths ;
24
- import java .util .Objects ;
25
22
import lombok .extern .slf4j .Slf4j ;
26
23
import org .apache .commons .lang3 .RandomStringUtils ;
27
24
import org .junit .jupiter .api .parallel .Isolated ;
@@ -47,7 +44,7 @@ public static void beforeAll() throws IOException {
47
44
sharedTempDir = Files .createDirectories (
48
45
Paths .get ("tmp/" + RandomStringUtils .randomAlphanumeric (8 ).toLowerCase () + "/" ));
49
46
container = new FlagdContainer ()
50
- .withFileSystemBind (sharedTempDir .toAbsolutePath ().toString (), "/tmp " , BindMode .READ_WRITE );
47
+ .withFileSystemBind (sharedTempDir .toAbsolutePath ().toString (), "/flags " , BindMode .READ_WRITE );
51
48
}
52
49
53
50
@ AfterAll
@@ -78,10 +75,15 @@ public void setupProvider(String providerType) throws IOException, InterruptedEx
78
75
String flagdConfig = "default" ;
79
76
state .builder .deadline (1000 ).keepAlive (0 ).retryGracePeriod (2 );
80
77
boolean wait = true ;
78
+
81
79
switch (providerType ) {
82
80
case "unavailable" :
83
81
this .state .providerType = ProviderType .SOCKET ;
84
82
state .builder .port (UNAVAILABLE_PORT );
83
+ if (State .resolverType == Config .Resolver .FILE ) {
84
+
85
+ state .builder .offlineFlagSourcePath ("not-existing" );
86
+ }
85
87
wait = false ;
86
88
break ;
87
89
case "socket" :
@@ -103,34 +105,28 @@ public void setupProvider(String providerType) throws IOException, InterruptedEx
103
105
.certPath (absolutePath );
104
106
flagdConfig = "ssl" ;
105
107
break ;
106
- case "offline" :
107
- State .resolverType = Config .Resolver .IN_PROCESS ;
108
- File flags = new File ("test-harness/flags" );
109
- ObjectMapper objectMapper = new ObjectMapper ();
110
- Object merged = new Object ();
111
- for (File listFile : Objects .requireNonNull (flags .listFiles ())) {
112
- ObjectReader updater = objectMapper .readerForUpdating (merged );
113
- merged = updater .readValue (listFile , Object .class );
114
- }
115
- Path offlinePath = Files .createTempFile ("flags" , ".json" );
116
- objectMapper .writeValue (offlinePath .toFile (), merged );
117
-
118
- state .builder
119
- .port (UNAVAILABLE_PORT )
120
- .offlineFlagSourcePath (offlinePath .toAbsolutePath ().toString ());
121
- break ;
122
108
123
109
default :
124
110
this .state .providerType = ProviderType .DEFAULT ;
125
- state .builder .port (container .getPort (State .resolverType ));
111
+ if (State .resolverType == Config .Resolver .FILE ) {
112
+
113
+ state .builder
114
+ .port (UNAVAILABLE_PORT )
115
+ .offlineFlagSourcePath (sharedTempDir
116
+ .resolve ("allFlags.json" )
117
+ .toAbsolutePath ()
118
+ .toString ());
119
+ } else {
120
+ state .builder .port (container .getPort (State .resolverType ));
121
+ }
126
122
break ;
127
123
}
128
124
when ().post ("http://" + container .getLaunchpadUrl () + "/start?config={config}" , flagdConfig )
129
125
.then ()
130
126
.statusCode (200 );
131
127
132
128
// giving flagd a little time to start
133
- Thread .sleep (100 );
129
+ Thread .sleep (30 );
134
130
FeatureProvider provider =
135
131
new FlagdProvider (state .builder .resolverType (State .resolverType ).build ());
136
132
@@ -159,10 +155,9 @@ public void the_connection_is_lost_for(int seconds) throws InterruptedException
159
155
160
156
@ When ("the flag was modified" )
161
157
public void the_flag_was_modded () throws InterruptedException {
162
-
163
158
when ().post ("http://" + container .getLaunchpadUrl () + "/change" ).then ().statusCode (200 );
164
159
165
160
// we might be too fast in the execution
166
- Thread .sleep (100 );
161
+ Thread .sleep (1000 );
167
162
}
168
163
}
0 commit comments