Skip to content

Commit bf9aa09

Browse files
author
greg-dennis
committed
Fix SetProperty and add unit test.
1 parent 15d215e commit bf9aa09

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

gtr/gtr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (p *Package) SetProperty(key, value string) {
7878
// then add the specieid key-value property.
7979
i := 0
8080
for _, prop := range p.Properties {
81-
if key == prop.Name {
81+
if key != prop.Name {
8282
p.Properties[i] = prop
8383
i++
8484
}

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+
}

0 commit comments

Comments
 (0)