@@ -302,4 +302,67 @@ void shouldExecuteOnCreateOrUpdate() throws Exception {
302302 Optional <Execution > updateExecution = trigger .evaluate (context .getKey (), context .getValue ());
303303 assertThat (updateExecution .isPresent (), is (true ));
304304 }
305+
306+ @ Test
307+ void maxFilesExceeded () throws Exception {
308+ String bucket = "trigger-maxfiles-exceeded" ;
309+ this .createBucket (bucket );
310+
311+ // Upload 5 files
312+ for (int i = 0 ; i < 5 ; i ++) {
313+ upload ("trigger/maxfiles" , bucket );
314+ }
315+
316+ // Trigger with maxFiles=3 (less than 5 files) - should fire with first 3 files (truncated)
317+ Trigger trigger = Trigger .builder ()
318+ .id ("s3-" + IdUtils .create ())
319+ .type (Trigger .class .getName ())
320+ .endpointOverride (Property .ofValue (localstack .getEndpointOverride (LocalStackContainer .Service .S3 ).toString ()))
321+ .accessKeyId (Property .ofValue (localstack .getAccessKey ()))
322+ .secretKeyId (Property .ofValue (localstack .getSecretKey ()))
323+ .region (Property .ofValue (localstack .getRegion ()))
324+ .bucket (Property .ofValue (bucket ))
325+ .prefix (Property .ofValue ("trigger/maxfiles" ))
326+ .action (Property .ofValue (ActionInterface .Action .NONE ))
327+ .maxFiles (Property .ofValue (3 ))
328+ .interval (Duration .ofSeconds (10 ))
329+ .build ();
330+
331+ Map .Entry <ConditionContext , io .kestra .core .models .triggers .Trigger > context = TestsUtils .mockTrigger (runContextFactory , trigger );
332+
333+ Optional <Execution > execution = trigger .evaluate (context .getKey (), context .getValue ());
334+ // When maxFiles exceeded, List returns first 3 files, so Trigger should fire
335+ assertThat (execution .isPresent (), is (true ));
336+ }
337+
338+ @ Test
339+ void maxFilesNotExceeded () throws Exception {
340+ String bucket = "trigger-maxfiles-ok" ;
341+ this .createBucket (bucket );
342+
343+ // Upload 5 files
344+ for (int i = 0 ; i < 5 ; i ++) {
345+ upload ("trigger/maxfiles-ok" , bucket );
346+ }
347+
348+ // Trigger with maxFiles=10 (more than 5 files) - should fire
349+ Trigger trigger = Trigger .builder ()
350+ .id ("s3-" + IdUtils .create ())
351+ .type (Trigger .class .getName ())
352+ .endpointOverride (Property .ofValue (localstack .getEndpointOverride (LocalStackContainer .Service .S3 ).toString ()))
353+ .accessKeyId (Property .ofValue (localstack .getAccessKey ()))
354+ .secretKeyId (Property .ofValue (localstack .getSecretKey ()))
355+ .region (Property .ofValue (localstack .getRegion ()))
356+ .bucket (Property .ofValue (bucket ))
357+ .prefix (Property .ofValue ("trigger/maxfiles-ok" ))
358+ .action (Property .ofValue (ActionInterface .Action .NONE ))
359+ .maxFiles (Property .ofValue (10 ))
360+ .interval (Duration .ofSeconds (10 ))
361+ .build ();
362+
363+ Map .Entry <ConditionContext , io .kestra .core .models .triggers .Trigger > context = TestsUtils .mockTrigger (runContextFactory , trigger );
364+
365+ Optional <Execution > execution = trigger .evaluate (context .getKey (), context .getValue ());
366+ assertThat (execution .isPresent (), is (true ));
367+ }
305368}
0 commit comments