apache / apache/grails-core

doWithConfig in unit test merges map instead of replacing

Open
#10,188 11 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-testing status: awaiting feedback status: in progress
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Steps to Reproduce

Add config to `application.groovy`:

```
foobar.foo = "1"
foobar.bar = ["1"]
foobar.baz = ["1" : "1"]
baz = ["1" : "1"]
```

`grails create-service Foo` and add these tests:

```
@TestFor(FooService)
class FooServiceSpec extends Specification {

static doWithConfig(c) {
c.foobar.foo = "2"
c.foobar.bar = ["2"]
c.foobar.baz = ["2": "2"]
c.baz = ["2": "2"]
}

void "test string"() {
expect:
grailsApplication.config.foobar.foo == "2"
}

void "test list"() {
expect:
grailsApplication.config.foobar.bar == ["2"]
}

void "test map one level"() {
expect:
grailsApplication.config.baz == ["2": "2"]
}

void "test map two levels"() {
expect:
grailsApplication.config.foobar.baz == ["2": "2"]
}

}
```
### Expected Behaviour

All tests should pass
### Actual Behaviour

The test "test map two levels" fails:

```
grailsApplication.config.foobar.baz == ["2": "2"]
| | | | |
| | | | false
| | | [1:1, 2:2]
| | [foo:2, bar:[2], baz:[1:1, 2:2]]
```

Note that the test "test map one level" runs fine, which means there are differences based on how deep the property is nested.
### Environment Information
- **Operating System**: OS X El Capitan
- **Grails Version:** 3.2.0
- **JDK Version:** 1.8.0_77
- **Container Version (If Applicable):**
### Example Application

https://github.com/rlovtangen/bugreport-grails-core-doWithConfig

Contributor guide

Open the contributing guide

Research direction

Start with the linked example application and its FooServiceSpec, then reproduce the nested-map case using application.groovy and doWithConfig. Trace how the test configuration is applied and compare the one-level and two-level map behavior. Done means the nested foobar.baz map is replaced with ["2": "2"] and all four tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.