codeconsole commented on code in PR #16130:
URL: https://github.com/apache/grails-core/pull/16130#discussion_r4350715357


##########
grails-core/src/test/groovy/org/grails/config/SystemEnvironmentConfigSpec.groovy:
##########
@@ -32,25 +33,21 @@ import java.lang.reflect.Field
  */
 class SystemEnvironmentConfigSpec extends Specification {
 
-    @Issue('#10670')
-    void 'configuration properties defined in SystemEnvironment take 
precedence'() {
-        given: 'default configuration in application-yml'
-        Resource resource1 = new ByteArrayResource('''
+    private static final String YAML = '''
 property.with.period: from-yml
 property_with_underscore: from-yml
 property-with-hyphen: from-yml
 property-with_mixed.symbols: from-yml
-'''.bytes, 'test.yml')
-
-        def propertySourceLoader = new YamlPropertySourceLoader()
-        def yamlPropertiesSource = 
propertySourceLoader.load('application.yml', resource1, null)
-        def propertySources = new MutablePropertySources()
-        propertySources.addFirst(yamlPropertiesSource.first())
-        def config = new PropertySourcesConfig(propertySources)
+'''
 
-        and: 'overriding value with system environment variable'
+    @Issue('#10670')
+    void 'configuration properties defined in SystemEnvironment take 
precedence'() {
+        given: 'a value in the system environment'
         modifiableSystemEnvironment.put(systemProperty, value)
 
+        and: 'default configuration in application-yml'
+        def config = configFor(YAML)
+
         expect:
         config.getProperty(propertyToFind) == value

Review Comment:
   Done in 9677aec218. `a null key resolves to the default value` pins 
`getProperty(null)`, `getProperty(null, String, 'dflt')` and 
`containsProperty(null)`; `a key is matched to its upper-cased variable under 
any default locale` sets `tr-TR` as the default locale around a lookup of 
`property.with.id` against `PROPERTY_WITH_ID` and restores it in `cleanup:`; 
and each row of the precedence table now carries its own value, 
`"from-${systemProperty}"`, so a row proves its own spelling.
   
   85a942591f sets the locale last and restores it first, so a failure to open 
the reflective environment cannot leave `tr-TR` behind for the rest of the fork.
   



##########
grails-core/src/test/groovy/org/grails/config/SystemEnvironmentConfigSpec.groovy:
##########
@@ -73,6 +73,56 @@ property-with_mixed.symbols: from-yml
         'property-with_mixed.symbols' | 'PROPERTY_WITH_MIXED_SYMBOLS' | 
'from-env'
     }
 
+    void 'a property read more than once keeps resolving to the system 
environment value'() {
+        given: 'configuration that is overridden by the environment'
+        def config = configFor('property.with.period: from-yml')
+        modifiableSystemEnvironment.put('PROPERTY_WITH_PERIOD', 'from-env')
+
+        expect: 'every read resolves to the environment value, not just the 
first'
+        config.getProperty('property.with.period') == 'from-env'
+        config.getProperty('property.with.period') == 'from-env'
+        config.getProperty('property.with.period') == 'from-env'
+
+        cleanup:
+        modifiableSystemEnvironment.remove('PROPERTY_WITH_PERIOD')
+    }
+
+    void 'a property that has already been read still reflects later 
configuration changes'() {
+        given: 'a property that has been read once'
+        def config = configFor('some.nested.value: original')
+        assert config.getProperty('some.nested.value') == 'original'

Review Comment:
   Applied in 5eb46c740d.
   



##########
grails-core/src/test/groovy/org/grails/config/SystemEnvironmentConfigSpec.groovy:
##########
@@ -73,6 +73,56 @@ property-with_mixed.symbols: from-yml
         'property-with_mixed.symbols' | 'PROPERTY_WITH_MIXED_SYMBOLS' | 
'from-env'
     }
 
+    void 'a property read more than once keeps resolving to the system 
environment value'() {
+        given: 'configuration that is overridden by the environment'
+        def config = configFor('property.with.period: from-yml')
+        modifiableSystemEnvironment.put('PROPERTY_WITH_PERIOD', 'from-env')
+
+        expect: 'every read resolves to the environment value, not just the 
first'
+        config.getProperty('property.with.period') == 'from-env'
+        config.getProperty('property.with.period') == 'from-env'
+        config.getProperty('property.with.period') == 'from-env'
+
+        cleanup:
+        modifiableSystemEnvironment.remove('PROPERTY_WITH_PERIOD')
+    }
+
+    void 'a property that has already been read still reflects later 
configuration changes'() {
+        given: 'a property that has been read once'
+        def config = configFor('some.nested.value: original')
+        assert config.getProperty('some.nested.value') == 'original'
+
+        when: 'the configuration is changed'
+        config.merge(['some.nested.value': 'updated'])
+
+        then: 'the new value is returned rather than the previously resolved 
one'
+        config.getProperty('some.nested.value') == 'updated'
+    }
+
+    void 'a config created after an environment variable is installed observes 
it'() {
+        given: 'a config created and read before the variable exists'
+        def before = configFor('late.bound.property: from-yml')
+        assert before.getProperty('late.bound.property') == 'from-yml'

Review Comment:
   Applied in 5eb46c740d.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to