Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Feb 26, 2019
1 parent 35df0fa commit f33024e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions metrics/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package metrics

import (
"context"
"errors"
"testing"
"time"

Expand All @@ -42,7 +43,7 @@ func TestReportTimingFromCtx(t *testing.T) {
originalTs := time.Now().UnixNano()
expectedRoute := uuid.New().String()
expectedType := uuid.New().String()
expectedErrored := true
expectedErr := errors.New(uuid.New().String())
ctx := pcontext.AddToPropagateCtx(context.Background(), constants.StartTimeKey, originalTs)
ctx = pcontext.AddToPropagateCtx(ctx, constants.RouteKey, expectedRoute)

Expand All @@ -53,7 +54,7 @@ func TestReportTimingFromCtx(t *testing.T) {
},
)

ReportTimingFromCtx(ctx, []Reporter{mockMetricsReporter}, expectedType, expectedErrored)
ReportTimingFromCtx(ctx, []Reporter{mockMetricsReporter}, expectedType, expectedErr)
})

t.Run("test-tags", func(t *testing.T) {
Expand All @@ -64,7 +65,7 @@ func TestReportTimingFromCtx(t *testing.T) {
originalTs := time.Now().UnixNano()
expectedRoute := uuid.New().String()
expectedType := uuid.New().String()
expectedErrored := false
var expectedErr error
ctx := pcontext.AddToPropagateCtx(context.Background(), constants.StartTimeKey, originalTs)
ctx = pcontext.AddToPropagateCtx(ctx, constants.RouteKey, expectedRoute)
ctx = pcontext.AddToPropagateCtx(ctx, constants.MetricTagsKey, map[string]string{
Expand All @@ -76,11 +77,12 @@ func TestReportTimingFromCtx(t *testing.T) {
"status": "ok",
"type": expectedType,
"key": "value",
"code": "",
}

mockMetricsReporter.EXPECT().ReportSummary(ResponseTime, expectedTags, gomock.Any())

ReportTimingFromCtx(ctx, []Reporter{mockMetricsReporter}, expectedType, expectedErrored)
ReportTimingFromCtx(ctx, []Reporter{mockMetricsReporter}, expectedType, expectedErr)
})

t.Run("test-tags-not-correct-type", func(t *testing.T) {
Expand All @@ -91,7 +93,7 @@ func TestReportTimingFromCtx(t *testing.T) {
originalTs := time.Now().UnixNano()
expectedRoute := uuid.New().String()
expectedType := uuid.New().String()
expectedErrored := false
var expectedErr error
ctx := pcontext.AddToPropagateCtx(context.Background(), constants.StartTimeKey, originalTs)
ctx = pcontext.AddToPropagateCtx(ctx, constants.RouteKey, expectedRoute)
ctx = pcontext.AddToPropagateCtx(ctx, constants.MetricTagsKey, "not-map")
Expand All @@ -100,11 +102,12 @@ func TestReportTimingFromCtx(t *testing.T) {
"route": expectedRoute,
"status": "ok",
"type": expectedType,
"code": "",
}

mockMetricsReporter.EXPECT().ReportSummary(ResponseTime, expectedTags, gomock.Any())

ReportTimingFromCtx(ctx, []Reporter{mockMetricsReporter}, expectedType, expectedErrored)
ReportTimingFromCtx(ctx, []Reporter{mockMetricsReporter}, expectedType, expectedErr)
})
}

Expand Down

0 comments on commit f33024e

Please sign in to comment.