3030import org .junit .jupiter .api .AfterEach ;
3131import org .junit .jupiter .api .BeforeAll ;
3232import org .junit .jupiter .api .Test ;
33- import org .junit .jupiter .api .extension .ExtendWith ;
3433
35- import org .springframework .boot .test .system .CapturedOutput ;
36- import org .springframework .boot .test .system .OutputCaptureExtension ;
3734import org .springframework .cloud .kubernetes .commons .config .ConfigUtils ;
3835import org .springframework .cloud .kubernetes .commons .config .LabeledConfigMapNormalizedSource ;
3936import org .springframework .cloud .kubernetes .commons .config .NormalizedSource ;
4542 * @author wind57
4643 */
4744@ EnableKubernetesMockClient (crud = true , https = false )
48- @ ExtendWith (OutputCaptureExtension .class )
49- class LabeledConfigMapContextToSourceDataProviderNonNamespacedBatchReadTests {
45+ class LabeledConfigMapContextToSourceDataProviderSingleReadTests {
5046
5147 private static final String NAMESPACE = "default" ;
5248
@@ -60,14 +56,12 @@ class LabeledConfigMapContextToSourceDataProviderNonNamespacedBatchReadTests {
6056
6157 private static KubernetesClient mockClient ;
6258
63- static {
64- LABELS .put ("label2" , "value2" );
65- LABELS .put ("label1" , "value1" );
66- }
67-
6859 @ BeforeAll
6960 static void beforeAll () {
7061
62+ LABELS .put ("label2" , "value2" );
63+ LABELS .put ("label1" , "value1" );
64+
7165 // Configure the kubernetes master url to point to the mock server
7266 System .setProperty (Config .KUBERNETES_MASTER_SYSTEM_PROPERTY , mockClient .getConfiguration ().getMasterUrl ());
7367 System .setProperty (Config .KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY , "true" );
@@ -102,7 +96,7 @@ void singleConfigMapMatchAgainstLabels() {
10296
10397 NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE , LABELS , true , false );
10498 Fabric8ConfigContext context = new Fabric8ConfigContext (mockClient , normalizedSource , NAMESPACE ,
105- new MockEnvironment (), ReadType .BATCH );
99+ new MockEnvironment (), ReadType .SINGLE );
106100
107101 Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider ().get ();
108102 SourceData sourceData = data .apply (context );
@@ -146,7 +140,7 @@ void twoConfigMapsMatchAgainstLabels() {
146140
147141 NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE , RED_LABEL , true , false );
148142 Fabric8ConfigContext context = new Fabric8ConfigContext (mockClient , normalizedSource , NAMESPACE ,
149- new MockEnvironment (), ReadType .BATCH );
143+ new MockEnvironment (), ReadType .SINGLE );
150144
151145 Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider ().get ();
152146 SourceData sourceData = data .apply (context );
@@ -175,7 +169,7 @@ void configMapNoMatch() {
175169
176170 NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE , BLUE_LABEL , true , false );
177171 Fabric8ConfigContext context = new Fabric8ConfigContext (mockClient , normalizedSource , NAMESPACE ,
178- new MockEnvironment (), ReadType .BATCH );
172+ new MockEnvironment (), ReadType .SINGLE );
179173
180174 Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider ().get ();
181175 SourceData sourceData = data .apply (context );
@@ -206,7 +200,7 @@ void namespaceMatch() {
206200 NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE + "nope" , LABELS , true ,
207201 false );
208202 Fabric8ConfigContext context = new Fabric8ConfigContext (mockClient , normalizedSource , NAMESPACE ,
209- new MockEnvironment (), ReadType .BATCH );
203+ new MockEnvironment (), ReadType .SINGLE );
210204
211205 Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider ().get ();
212206 SourceData sourceData = data .apply (context );
@@ -236,7 +230,7 @@ void testWithPrefix() {
236230 NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE ,
237231 Collections .singletonMap ("color" , "blue" ), true , mePrefix , false );
238232 Fabric8ConfigContext context = new Fabric8ConfigContext (mockClient , normalizedSource , NAMESPACE ,
239- new MockEnvironment (), ReadType .BATCH );
233+ new MockEnvironment (), ReadType .SINGLE );
240234
241235 Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider ().get ();
242236 SourceData sourceData = data .apply (context );
@@ -278,7 +272,7 @@ void testTwoConfigmapsWithPrefix() {
278272 NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE ,
279273 Collections .singletonMap ("color" , "blue" ), true , ConfigUtils .Prefix .DELAYED , false );
280274 Fabric8ConfigContext context = new Fabric8ConfigContext (mockClient , normalizedSource , NAMESPACE ,
281- new MockEnvironment (), ReadType .BATCH );
275+ new MockEnvironment (), ReadType .SINGLE );
282276
283277 Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider ().get ();
284278 SourceData sourceData = data .apply (context );
@@ -328,7 +322,7 @@ void searchWithLabelsNoConfigmapsFound() {
328322 NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE ,
329323 Collections .singletonMap ("color" , "red" ), true , ConfigUtils .Prefix .DEFAULT , true );
330324 Fabric8ConfigContext context = new Fabric8ConfigContext (mockClient , normalizedSource , NAMESPACE , environment ,
331- ReadType .BATCH );
325+ ReadType .SINGLE );
332326
333327 Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider ().get ();
334328 SourceData sourceData = data .apply (context );
@@ -365,7 +359,7 @@ void searchWithLabelsOneConfigMapFound() {
365359 NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE ,
366360 Collections .singletonMap ("color" , "blue" ), true , ConfigUtils .Prefix .DEFAULT , true );
367361 Fabric8ConfigContext context = new Fabric8ConfigContext (mockClient , normalizedSource , NAMESPACE , environment ,
368- ReadType .BATCH );
362+ ReadType .SINGLE );
369363
370364 Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider ().get ();
371365 SourceData sourceData = data .apply (context );
@@ -433,7 +427,7 @@ void searchWithLabelsTwoConfigMapsFound() {
433427 NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE ,
434428 Collections .singletonMap ("color" , "blue" ), true , ConfigUtils .Prefix .DELAYED , true );
435429 Fabric8ConfigContext context = new Fabric8ConfigContext (mockClient , normalizedSource , NAMESPACE , environment ,
436- ReadType .BATCH );
430+ ReadType .SINGLE );
437431
438432 Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider ().get ();
439433 SourceData sourceData = data .apply (context );
@@ -455,7 +449,7 @@ void searchWithLabelsTwoConfigMapsFound() {
455449 * </pre>
456450 */
457451 @ Test
458- void nonCache (CapturedOutput output ) {
452+ void nonCache () {
459453 ConfigMap redConfigMap = new ConfigMapBuilder ().withNewMetadata ()
460454 .withName ("red-configmap" )
461455 .withLabels (Collections .singletonMap ("color" , "red" ))
@@ -478,34 +472,32 @@ void nonCache(CapturedOutput output) {
478472 NormalizedSource redNormalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE ,
479473 Collections .singletonMap ("color" , "red" ), true , ConfigUtils .Prefix .DELAYED , true );
480474 Fabric8ConfigContext redContext = new Fabric8ConfigContext (mockClient , redNormalizedSource , NAMESPACE ,
481- environment , ReadType .BATCH );
475+ environment , ReadType .SINGLE );
482476 Fabric8ContextToSourceData redData = new LabeledConfigMapContextToSourceDataProvider ().get ();
483477 SourceData redSourceData = redData .apply (redContext );
484478
485479 Assertions .assertThat (redSourceData .sourceData ()).hasSize (1 );
486480 Assertions .assertThat (redSourceData .sourceData ().get ("red-configmap.one" )).isEqualTo ("1" );
487481
488- Assertions .assertThat (output .getAll ())
489- .doesNotContain ("Loaded all config maps in namespace '" + NAMESPACE + "'" );
490- Assertions .assertThat (output .getOut ()).contains ("Will read individual configmaps in namespace" );
491-
492482 NormalizedSource greenNormalizedSource = new LabeledConfigMapNormalizedSource (NAMESPACE ,
493483 Collections .singletonMap ("color" , "green" ), true , ConfigUtils .Prefix .DELAYED , true );
494484 Fabric8ConfigContext greenContext = new Fabric8ConfigContext (mockClient , greenNormalizedSource , NAMESPACE ,
495- environment , ReadType .BATCH );
485+ environment , ReadType .SINGLE );
496486 Fabric8ContextToSourceData greenData = new LabeledConfigMapContextToSourceDataProvider ().get ();
497487 SourceData greenSourceData = greenData .apply (greenContext );
498488
499489 Assertions .assertThat (greenSourceData .sourceData ()).hasSize (1 );
500490 Assertions .assertThat (greenSourceData .sourceData ().get ("green-configmap.two" )).isEqualTo ("2" );
501491
502- // meaning there is a single entry with such a log statement
503- String [] out = output .getAll ().split ("Loaded all config maps in namespace" );
504- Assertions .assertThat (out .length ).isEqualTo (1 );
492+ // since we do SINGLE reads, thus no caching is involved
493+ // when we remove the configmap, nothing is found
494+ mockClient .configMaps ().inNamespace (NAMESPACE ).resource (greenConfigmap ).delete ();
495+
496+ greenData = new LabeledConfigMapContextToSourceDataProvider ().get ();
497+ greenSourceData = greenData .apply (greenContext );
505498
506- // meaning that both reads were non cached
507- out = output .getAll ().split ("Will read individual configmaps in namespace" );
508- Assertions .assertThat (out .length ).isEqualTo (3 );
499+ Assertions .assertThat (greenSourceData .sourceData ()).hasSize (0 );
500+ Assertions .assertThat (greenSourceData .sourceData ().get ("green-configmap.two" )).isNull ();
509501
510502 }
511503
0 commit comments