Skip to content

Commit

Permalink
Add unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnWu20 committed Mar 4, 2021
1 parent 834bb1b commit 543d60f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
4 changes: 2 additions & 2 deletions receiver/awsxrayreceiver/internal/translator/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func addHTTP(seg *awsxray.Segment, span *pdata.Span) {
case string:
lengthPointer := resp.ContentLength.(string)
addString(&lengthPointer, conventions.AttributeHTTPResponseContentLength, &attrs)
case int:
length := resp.ContentLength.(int)
case float64:
length := resp.ContentLength.(float64)
lengthPointer := int64(length)
addInt64(&lengthPointer, conventions.AttributeHTTPResponseContentLength, &attrs)
}
Expand Down
43 changes: 11 additions & 32 deletions receiver/awsxrayreceiver/internal/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,9 @@ func TestTranslation(t *testing.T) {
*subseg7318.Name)
childSpan7318Attrs[conventions.AttributeHTTPStatusCode] = pdata.NewAttributeValueInt(
*subseg7318.HTTP.Response.Status)
switch subseg7318.HTTP.Response.ContentLength.(type) {
case int:
contentLength := subseg7318.HTTP.Response.ContentLength.(int64)
childSpan7318Attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueInt(contentLength)
case string:
contentLength := subseg7318.HTTP.Response.ContentLength.(string)
childSpan7318Attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueString(contentLength)
}

contentLength := subseg7318.HTTP.Response.ContentLength.(float64)
childSpan7318Attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueInt(int64(contentLength))
childSpan7318Attrs[awsxray.AWSOperationAttribute] = pdata.NewAttributeValueString(
*subseg7318.AWS.Operation)
childSpan7318Attrs[awsxray.AWSRegionAttribute] = pdata.NewAttributeValueString(
Expand Down Expand Up @@ -411,14 +406,8 @@ func TestTranslation(t *testing.T) {
*subseg7163.Name)
childSpan7163Attrs[conventions.AttributeHTTPStatusCode] = pdata.NewAttributeValueInt(
*subseg7163.HTTP.Response.Status)
switch subseg7163.HTTP.Response.ContentLength.(type) {
case int:
contentLength := subseg7163.HTTP.Response.ContentLength.(int64)
childSpan7163Attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueInt(contentLength)
case string:
contentLength := subseg7163.HTTP.Response.ContentLength.(string)
childSpan7163Attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueString(contentLength)
}
contentLength = subseg7163.HTTP.Response.ContentLength.(float64)
childSpan7163Attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueInt(int64(contentLength))
childSpan7163Attrs[awsxray.AWSOperationAttribute] = pdata.NewAttributeValueString(
*subseg7163.AWS.Operation)
childSpan7163Attrs[awsxray.AWSRegionAttribute] = pdata.NewAttributeValueString(
Expand Down Expand Up @@ -730,14 +719,8 @@ func TestTranslation(t *testing.T) {
*seg.HTTP.Response.Status)
attrs[conventions.AttributeHTTPURL] = pdata.NewAttributeValueString(
*seg.HTTP.Request.URL)
switch seg.HTTP.Response.ContentLength.(type) {
case int:
contentLength := seg.HTTP.Response.ContentLength.(int64)
attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueInt(contentLength)
case string:
contentLength := seg.HTTP.Response.ContentLength.(string)
attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueString(contentLength)
}
contentLength := seg.HTTP.Response.ContentLength.(float64)
attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueInt(int64(contentLength))
attrs[awsxray.AWSXRayTracedAttribute] = pdata.NewAttributeValueBool(true)
res := perSpanProperties{
traceID: *seg.TraceID,
Expand Down Expand Up @@ -781,14 +764,10 @@ func TestTranslation(t *testing.T) {
*seg.HTTP.Response.Status)
attrs[conventions.AttributeHTTPURL] = pdata.NewAttributeValueString(
*seg.HTTP.Request.URL)
switch seg.HTTP.Response.ContentLength.(type) {
case int:
contentLength := seg.HTTP.Response.ContentLength.(int64)
attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueInt(contentLength)
case string:
contentLength := seg.HTTP.Response.ContentLength.(string)
attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueString(contentLength)
}

contentLength := seg.HTTP.Response.ContentLength.(string)
attrs[conventions.AttributeHTTPResponseContentLength] = pdata.NewAttributeValueString(contentLength)

attrs[awsxray.AWSXRayTracedAttribute] = pdata.NewAttributeValueBool(true)
res := perSpanProperties{
traceID: *seg.TraceID,
Expand Down

0 comments on commit 543d60f

Please sign in to comment.