Omit empty <properties> tag when there are no properties.

Go doesn't omit empty parent tags for empty values[1], so we'll work
around this for now by creating a pointer to the property slice.

[1]: https://github.com/golang/go/issues/7233.
This commit is contained in:
Joël Stemmer
2022-03-11 23:36:03 +00:00
parent 43c784a63b
commit 458fe89a9a
3 changed files with 43 additions and 15 deletions

View File

@ -48,15 +48,21 @@ type Testsuite struct {
Time string `xml:"time,attr"` // duration in seconds
Timestamp string `xml:"timestamp,attr,omitempty"` // date and time in ISO8601
Properties []Property `xml:"properties>property,omitempty"`
Testcases []Testcase `xml:"testcase,omitempty"`
SystemOut *Output `xml:"system-out,omitempty"`
SystemErr *Output `xml:"system-err,omitempty"`
Properties *[]Property `xml:"properties>property,omitempty"`
Testcases []Testcase `xml:"testcase,omitempty"`
SystemOut *Output `xml:"system-out,omitempty"`
SystemErr *Output `xml:"system-err,omitempty"`
}
// AddProperty adds a property with the given name and value to this Testsuite.
func (t *Testsuite) AddProperty(name, value string) {
t.Properties = append(t.Properties, Property{Name: name, Value: value})
prop := Property{Name: name, Value: value}
if t.Properties == nil {
t.Properties = &[]Property{prop}
return
}
props := append(*t.Properties, prop)
t.Properties = &props
}
// AddTestcase adds Testcase tc to this Testsuite.