Skip to content

Commit

Permalink
fix(test): fixup test case of sort of map keys
Browse files Browse the repository at this point in the history
Signed-off-by: slasher <[email protected]>
  • Loading branch information
sejust committed Jul 4, 2023
1 parent ab2659a commit 661559c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 1 addition & 6 deletions blobstore/common/trace/span_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ func (s *SpanContext) append(value string) {
s.baggage = map[string][]string{internalTrackLogKey: {value}}
return
}

if _, ok := s.baggage[internalTrackLogKey]; ok {
s.baggage[internalTrackLogKey] = append(s.baggage[internalTrackLogKey], value)
return
}
s.baggage[internalTrackLogKey] = []string{value}
s.baggage[internalTrackLogKey] = append(s.baggage[internalTrackLogKey], value)
}

func (s *SpanContext) baggageItem(key string) []string {
Expand Down
8 changes: 8 additions & 0 deletions blobstore/common/trace/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ func TestSpan_TrackLog(t *testing.T) {

spanChild.AppendTrackLog("sleep3", time.Now(), nil)
require.Equal(t, []string{"sleep", "sleep2/sleep2 err", "blobnode:4", "scheduler:5", "sleep3"}, span.TrackLog())

msg := make([]byte, maxErrorLen+10)
for idx := range msg {
msg[idx] = 97
}
spanChild.AppendTrackLog("longError", time.Now(), errors.New(string(msg)))
except := "longError/" + string(msg[:maxErrorLen])
require.Equal(t, except, span.TrackLog()[len(span.TrackLog())-1])
}

func TestSpan_TrackLogWithDuration(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion blobstore/common/trace/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package trace
import (
"context"
"net/http"
"sort"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -46,7 +47,9 @@ func TestExplicitTags(t *testing.T) {
"tag2K": "tag2V",
}

require.Equal(t, []string{"tag1K:tag1V", "tag2K:tag2V"}, tags.ToSlice())
slice := tags.ToSlice()
sort.Strings(slice)
require.Equal(t, []string{"tag1K:tag1V", "tag2K:tag2V"}, slice)
_, err := tags.Marshal()
require.NoError(t, err)

Expand Down

0 comments on commit 661559c

Please sign in to comment.