@@ -410,6 +410,56 @@ void aggregate_supplierReturnsSameInstanceMultipleTimesAggregatingProfileFileSup
410
410
assertThat (suppliedProfileFiles ).isEqualTo (distinctAggregateProfileFiles );
411
411
}
412
412
413
+ @ Test
414
+ void aggregate_duplicateOptionsGivenFixedProfileFirst_preservesPrecedence () {
415
+ ProfileFile configFile1 = configFile ("profile default" , Pair .of ("aws_access_key_id" , "config-key" ));
416
+ Path credentialsFilePath = generateTestCredentialsFile ("defaultAccessKey" , "defaultSecretAccessKey" );
417
+
418
+ ProfileFileSupplier supplier = ProfileFileSupplier .aggregate (
419
+ ProfileFileSupplier .fixedProfileFile (configFile1 ),
420
+ ProfileFileSupplier .reloadWhenModified (credentialsFilePath , ProfileFile .Type .CREDENTIALS ));
421
+
422
+ ProfileFile profileFile = supplier .get ();
423
+ String accessKeyId = profileFile .profile ("default" ).get ().property ("aws_access_key_id" ).get ();
424
+
425
+ assertThat (accessKeyId ).isEqualTo ("config-key" );
426
+
427
+ generateTestCredentialsFile ("defaultAccessKey2" , "defaultSecretAccessKey2" );
428
+
429
+ profileFile = supplier .get ();
430
+ accessKeyId = profileFile .profile ("default" ).get ().property ("aws_access_key_id" ).get ();
431
+
432
+ assertThat (accessKeyId ).isEqualTo ("config-key" );
433
+ }
434
+
435
+ @ Test
436
+ void aggregate_duplicateOptionsGivenReloadingProfileFirst_preservesPrecedence () throws InterruptedException {
437
+ AdjustableClock clock = new AdjustableClock ();
438
+
439
+ ProfileFile configFile1 = configFile ("profile default" , Pair .of ("aws_access_key_id" , "config-key" ));
440
+ Path credentialsFilePath = generateTestCredentialsFile ("defaultAccessKey" , "defaultSecretAccessKey" );
441
+
442
+ ProfileFileSupplier supplier = ProfileFileSupplier .aggregate (
443
+ builderWithClock (clock )
444
+ .reloadWhenModified (credentialsFilePath , ProfileFile .Type .CREDENTIALS )
445
+ .build (),
446
+ ProfileFileSupplier .fixedProfileFile (configFile1 ));
447
+
448
+ ProfileFile profileFile = supplier .get ();
449
+ String accessKeyId = profileFile .profile ("default" ).get ().property ("aws_access_key_id" ).get ();
450
+
451
+ assertThat (accessKeyId ).isEqualTo ("defaultAccessKey" );
452
+
453
+ generateTestCredentialsFile ("defaultAccessKey2" , "defaultSecretAccessKey2" );
454
+
455
+ clock .tickForward (Duration .ofMillis (1_000 ));
456
+
457
+ profileFile = supplier .get ();
458
+ accessKeyId = profileFile .profile ("default" ).get ().property ("aws_access_key_id" ).get ();
459
+
460
+ assertThat (accessKeyId ).isEqualTo ("defaultAccessKey2" );
461
+ }
462
+
413
463
@ Test
414
464
void fixedProfileFile_nullProfileFile_returnsNonNullSupplier () {
415
465
ProfileFile file = null ;
0 commit comments