fix(add): stop four more generators emitting empty lists - #1113
Open
VXNCXNX wants to merge 1 commit into
Open
Conversation
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
make test-all(UNIX) passes. CI will also test this (the Makefile has notest-alltarget; ranmake test-short-all, which isfmt lint vet test, all green, plusgolangci-lint runexplicitly since the make step could not find the binary on PATH:0 issues.. The Docker-basedintegration-tests/test.shthat diffs the updated fixtures was not run here)Description of change
Same defect as #1111 and #1112, at the three remaining generators of that shape plus
user. No separate issue is filed for this one.What's broken
Four more generators write an empty list into the gossfile they produce, so validating goss's own output warns about it.
Same for
add dnson a host that does not resolve,add interfaceon an interface with no addresses, andadd userfor a user in no groups.The fix
The fields are declared
matcher, which isany, withomitempty. Assigning a typed nil slice into ananyleaves the interface value non-nil, soomitemptydoes not fire and yaml.v3 writes[]:So each generator now only assigns when the slice is non-empty, letting
omitemptydrop the key. The system getters that produce these areDefPort.IP(var ips []string, no append when the port has no entries),DefDNS.Addrs(d.addrsstays nil for an unresolvable host),DefInterface.Addrs(var ret []string), andGroups, where the unix path starts from[]string{}, non-nil and empty, and the windows path can return nil.Ruled out and left alone:
mount.optsandmount.vfs-opts, because a mounted filesystem always carries at leastrworroandsetup()errors out for a missing mountpoint, andservice.runlevels, whichNewServicenever assigns in the first place.Fixtures
integration-tests/goss/*/goss-expected.yamlcarriedip: []fortcp:9999andtcp6:80on four distros. Those files are generated output diffed byintegration-tests/test.shunder Docker, whichgo testdoes not run, so they are updated here the same way #1112 updated them. The hand-written inputs, and theopts: []entries undertests/, which sit behindskip: true, are untouched.Verification
A regression test per field asserting the key is absent from the marshalled yaml, plus a companion asserting a real value still survives, driven by minimal fake
system.*implementations in the #1112 style. With the four guards reverted all four regression tests fail and all four companions still pass.go test ./...passes.Disclosure: written with AI assistance (Claude Code). I reproduced the issue, ran the change and the verification myself.