Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue with missing test detection #7783

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions tools/missing-test-detector/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,7 @@ func readHCLBlockBody(body hcl.Body, fileBytes []byte) (Resource, error) {
if existing, ok := m[block.Type]; ok {
// Merge the fields from the current block into the existing resource config.
if existingResource, ok := existing.(Resource); ok {
for k, v := range blockConfig {
if _, ok := existingResource[k]; !ok {
existingResource[k] = v
}
}
mergeResources(existingResource, blockConfig)
}
} else {
m[block.Type] = blockConfig
Expand All @@ -292,3 +288,18 @@ func readHCLBlockBody(body hcl.Body, fileBytes []byte) (Resource, error) {
}
return m, nil
}

// Perform a recursive one-way merge of b into a.
func mergeResources(a, b Resource) {
for k, bv := range b {
if av, ok := a[k]; ok {
if avr, ok := av.(Resource); ok {
if bvr, ok := bv.(Resource); ok {
mergeResources(avr, bvr)
}
}
} else {
a[k] = bv
}
}
}