Skip to content

Commit 917d9f7

Browse files
authored
Merge pull request #143 from greg-dennis/master
Report stores a slice of Property structs instead of a map
2 parents 35c4d8a + bf9aa09 commit 917d9f7

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
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.

gtr/gtr_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package gtr
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"github.com/google/go-cmp/cmp"
7+
)
48

59
func TestTrimPrefixSpaces(t *testing.T) {
610
tests := []struct {
@@ -24,3 +28,15 @@ func TestTrimPrefixSpaces(t *testing.T) {
2428
}
2529
}
2630
}
31+
32+
func TestSetProperty(t *testing.T) {
33+
pkg := Package{}
34+
pkg.SetProperty("a", "b")
35+
pkg.SetProperty("c", "d")
36+
pkg.SetProperty("a", "e")
37+
38+
want := []Property{{Name: "c", Value: "d"}, {Name: "a", Value: "e"}}
39+
if diff := cmp.Diff(want, pkg.Properties); diff != "" {
40+
t.Errorf("SetProperty got unexpected diff: %s", diff)
41+
}
42+
}

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)