Remove dependency to testify/assert library
Daniel Furman
7 years ago
1 | 1 | |
2 | 2 | import ( |
3 | 3 | "net/http" |
4 | "reflect" | |
4 | 5 | "testing" |
5 | 6 | |
6 | 7 | "github.com/opentracing/opentracing-go" |
7 | 8 | "github.com/opentracing/opentracing-go/ext" |
8 | 9 | "github.com/opentracing/opentracing-go/mocktracer" |
9 | "github.com/stretchr/testify/assert" | |
10 | 10 | "golang.org/x/net/context" |
11 | 11 | |
12 | 12 | "github.com/go-kit/kit/log" |
73 | 73 | |
74 | 74 | kitot.ToHTTPRequest(tracer, log.NewNopLogger())(ctx, req) |
75 | 75 | |
76 | assert.Equal(t, map[string]interface{}{ | |
76 | expectedTags := map[string]interface{}{ | |
77 | 77 | string(ext.HTTPMethod): "GET", |
78 | 78 | string(ext.HTTPUrl): "http://test.biz/path", |
79 | 79 | string(ext.PeerHostname): "test.biz", |
80 | }, span.Tags()) | |
80 | } | |
81 | if !reflect.DeepEqual(expectedTags, span.Tags()) { | |
82 | t.Errorf("Want %q, have %q", expectedTags, span.Tags()) | |
83 | } | |
81 | 84 | } |
82 | 85 | |
83 | 86 | func TestFromHTTPRequestTags(t *testing.T) { |
91 | 94 | opentracing.SpanFromContext(ctx).Finish() |
92 | 95 | |
93 | 96 | childSpan := tracer.FinishedSpans()[0] |
94 | assert.Equal(t, "op", childSpan.OperationName) | |
95 | assert.Equal(t, map[string]interface{}{ | |
97 | expectedTags := map[string]interface{}{ | |
96 | 98 | string(ext.HTTPMethod): "GET", |
97 | 99 | string(ext.HTTPUrl): "http://test.biz/path", |
98 | 100 | string(ext.SpanKind): ext.SpanKindRPCServerEnum, |
99 | }, childSpan.Tags()) | |
101 | } | |
102 | if !reflect.DeepEqual(expectedTags, childSpan.Tags()) { | |
103 | t.Errorf("Want %q, have %q", expectedTags, childSpan.Tags()) | |
104 | } | |
105 | if want, have := "op", childSpan.OperationName; want != have { | |
106 | t.Errorf("Want %q, have %q", want, have) | |
107 | } | |
100 | 108 | } |