Skip to content

Commit 15d215e

Browse files
author
greg-dennis
committed
Report stores a slice of Property structs rather than a map, to mimic JUnit properties, which have a deterministic ordering and allow multipler properties with the same name.
1 parent 35c4d8a commit 15d215e

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

gtr/gtr.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type Package struct {
6161
Duration time.Duration
6262
Coverage float64
6363
Output []string
64-
Properties map[string]string
64+
Properties []Property
6565

6666
Tests []Test
6767

@@ -73,10 +73,28 @@ type Package struct {
7373
// property with the given key already exists, its old value will be
7474
// overwritten with the given value.
7575
func (p *Package) SetProperty(key, value string) {
76-
if p.Properties == nil {
77-
p.Properties = make(map[string]string)
76+
// TODO(jstemmer): Delete this method in the next major release.
77+
// Delete all the properties whose name is the specified key,
78+
// then add the specieid key-value property.
79+
i := 0
80+
for _, prop := range p.Properties {
81+
if key == prop.Name {
82+
p.Properties[i] = prop
83+
i++
84+
}
7885
}
79-
p.Properties[key] = value
86+
p.Properties = p.Properties[:i]
87+
p.AddProperty(key, value)
88+
}
89+
90+
// AddProperty appends a name/value property in the current package.
91+
func (p *Package) AddProperty(name, value string) {
92+
p.Properties = append(p.Properties, Property{Name: name, Value: value})
93+
}
94+
95+
// Property is a name/value property.
96+
type Property struct {
97+
Name, Value string
8098
}
8199

82100
// Test contains the results of a single test.

junit/junit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ func CreateFromReport(report gtr.Report, hostname string) Testsuites {
144144
suite.SetTimestamp(pkg.Timestamp)
145145
}
146146

147-
for k, v := range pkg.Properties {
148-
suite.AddProperty(k, v)
147+
for _, p := range pkg.Properties {
148+
suite.AddProperty(p.Name, p.Value)
149149
}
150150

151151
if len(pkg.Output) > 0 {

junit/junit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestCreateFromReport(t *testing.T) {
1919
Duration: 1 * time.Second,
2020
Coverage: 0.9,
2121
Output: []string{"output"},
22-
Properties: map[string]string{"go.version": "go1.18"},
22+
Properties: []gtr.Property{{Name: "go.version", Value: "go1.18"}},
2323
Tests: []gtr.Test{
2424
{
2525
Name: "TestPass",

0 commit comments

Comments
 (0)