diff --git a/gtr/gtr.go b/gtr/gtr.go index a8f438d..c205123 100644 --- a/gtr/gtr.go +++ b/gtr/gtr.go @@ -61,7 +61,7 @@ type Package struct { Duration time.Duration Coverage float64 Output []string - Properties map[string]string + Properties []Property Tests []Test @@ -73,10 +73,28 @@ type Package struct { // property with the given key already exists, its old value will be // overwritten with the given value. func (p *Package) SetProperty(key, value string) { - if p.Properties == nil { - p.Properties = make(map[string]string) + // TODO(jstemmer): Delete this method in the next major release. + // Delete all the properties whose name is the specified key, + // then add the specieid key-value property. + i := 0 + for _, prop := range p.Properties { + if key == prop.Name { + p.Properties[i] = prop + i++ + } } - p.Properties[key] = value + p.Properties = p.Properties[:i] + p.AddProperty(key, value) +} + +// AddProperty appends a name/value property in the current package. +func (p *Package) AddProperty(name, value string) { + p.Properties = append(p.Properties, Property{Name: name, Value: value}) +} + +// Property is a name/value property. +type Property struct { + Name, Value string } // Test contains the results of a single test. diff --git a/junit/junit.go b/junit/junit.go index f02e21f..8d23e53 100644 --- a/junit/junit.go +++ b/junit/junit.go @@ -144,8 +144,8 @@ func CreateFromReport(report gtr.Report, hostname string) Testsuites { suite.SetTimestamp(pkg.Timestamp) } - for k, v := range pkg.Properties { - suite.AddProperty(k, v) + for _, p := range pkg.Properties { + suite.AddProperty(p.Name, p.Value) } if len(pkg.Output) > 0 { diff --git a/junit/junit_test.go b/junit/junit_test.go index 2827ec8..a19478c 100644 --- a/junit/junit_test.go +++ b/junit/junit_test.go @@ -19,7 +19,7 @@ func TestCreateFromReport(t *testing.T) { Duration: 1 * time.Second, Coverage: 0.9, Output: []string{"output"}, - Properties: map[string]string{"go.version": "go1.18"}, + Properties: []gtr.Property{{Name: "go.version", Value: "go1.18"}}, Tests: []gtr.Test{ { Name: "TestPass",