Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Tracestate.Entries should work on nil *Tracestate (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Nogueira committed Sep 8, 2018
1 parent d3ed4d2 commit b11f239
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions trace/tracestate/tracestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type Entry struct {

// Entries returns a slice of Entry.
func (ts *Tracestate) Entries() []Entry {
if ts == nil {
return nil
}
return ts.entries
}

Expand Down
10 changes: 10 additions & 0 deletions trace/tracestate/tracestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,13 @@ func TestCreateFromArrayWithDuplicateKeys(t *testing.T) {
wantError(t, tracestate, err, testname,
"create did not err when entries contained duplicate keys")
}

func TestEntriesWithNil(t *testing.T) {
ts, err := New(nil)
if err != nil {
t.Fatal(err)
}
if got, want := len(ts.Entries()), 0; got != want {
t.Errorf("zero value should have no entries, got %v; want %v", got, want)
}
}

0 comments on commit b11f239

Please sign in to comment.