diff --git a/exporter/awsemfexporter/grouped_metric_test.go b/exporter/awsemfexporter/grouped_metric_test.go index e7c176f82b01..d2b1a86610f0 100644 --- a/exporter/awsemfexporter/grouped_metric_test.go +++ b/exporter/awsemfexporter/grouped_metric_test.go @@ -435,7 +435,7 @@ func TestAddKubernetesWrapper(t *testing.T) { jsonBytes, _ := json.Marshal(expectedCreatedObj) addKubernetesWrapper(inputs) - assert.Equal(t, string(jsonBytes), inputs["kubernetes"], "The created and expected objects should be the same") + assert.JSONEq(t, string(jsonBytes), inputs["kubernetes"], "The created and expected objects should be the same") }) } diff --git a/exporter/awsxrayexporter/internal/translator/cause_test.go b/exporter/awsxrayexporter/internal/translator/cause_test.go index 0369d7066d73..6f4dbfcd9eb0 100644 --- a/exporter/awsxrayexporter/internal/translator/cause_test.go +++ b/exporter/awsxrayexporter/internal/translator/cause_test.go @@ -193,7 +193,7 @@ func TestCauseWithStatusMessage(t *testing.T) { require.NoError(t, w.Encode(cause)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, errorMsg)) + assert.Contains(t, jsonStr, errorMsg) } func TestCauseWithHttpStatusMessage(t *testing.T) { @@ -218,7 +218,7 @@ func TestCauseWithHttpStatusMessage(t *testing.T) { require.NoError(t, w.Encode(cause)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, errorMsg)) + assert.Contains(t, jsonStr, errorMsg) } func TestCauseWithZeroStatusMessageAndFaultHttpCode(t *testing.T) { diff --git a/exporter/awsxrayexporter/internal/translator/http_test.go b/exporter/awsxrayexporter/internal/translator/http_test.go index f34c4e82af59..d0f8b375c72f 100644 --- a/exporter/awsxrayexporter/internal/translator/http_test.go +++ b/exporter/awsxrayexporter/internal/translator/http_test.go @@ -4,7 +4,6 @@ package translator import ( - "strings" "testing" "time" @@ -31,7 +30,7 @@ func TestClientSpanWithURLAttribute(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) + assert.Contains(t, jsonStr, "https://api.example.com/users/junit") } func TestClientSpanWithURLAttributeStable(t *testing.T) { @@ -49,7 +48,7 @@ func TestClientSpanWithURLAttributeStable(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) + assert.Contains(t, jsonStr, "https://api.example.com/users/junit") } func TestClientSpanWithSchemeHostTargetAttributes(t *testing.T) { @@ -70,7 +69,7 @@ func TestClientSpanWithSchemeHostTargetAttributes(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) + assert.Contains(t, jsonStr, "https://api.example.com/users/junit") } func TestClientSpanWithPeerAttributes(t *testing.T) { @@ -95,7 +94,7 @@ func TestClientSpanWithPeerAttributes(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "http://kb234.example.com:8080/users/junit")) + assert.Contains(t, jsonStr, "http://kb234.example.com:8080/users/junit") } func TestClientSpanWithPeerAttributesStable(t *testing.T) { @@ -120,7 +119,7 @@ func TestClientSpanWithPeerAttributesStable(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "http://kb234.example.com:8080/users/junit")) + assert.Contains(t, jsonStr, "http://kb234.example.com:8080/users/junit") } func TestClientSpanWithHttpPeerAttributes(t *testing.T) { @@ -168,7 +167,7 @@ func TestClientSpanWithPeerIp4Attributes(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "http://10.8.17.36:8080/users/junit")) + assert.Contains(t, jsonStr, "http://10.8.17.36:8080/users/junit") } func TestClientSpanWithPeerIp6Attributes(t *testing.T) { @@ -187,7 +186,7 @@ func TestClientSpanWithPeerIp6Attributes(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://2001:db8:85a3::8a2e:370:7334/users/junit")) + assert.Contains(t, jsonStr, "https://2001:db8:85a3::8a2e:370:7334/users/junit") } func TestServerSpanWithURLAttribute(t *testing.T) { @@ -207,7 +206,7 @@ func TestServerSpanWithURLAttribute(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) + assert.Contains(t, jsonStr, "https://api.example.com/users/junit") } func TestServerSpanWithURLAttributeStable(t *testing.T) { @@ -227,7 +226,7 @@ func TestServerSpanWithURLAttributeStable(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) + assert.Contains(t, jsonStr, "https://api.example.com/users/junit") } func TestServerSpanWithSchemeHostTargetAttributes(t *testing.T) { @@ -248,7 +247,7 @@ func TestServerSpanWithSchemeHostTargetAttributes(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) + assert.Contains(t, jsonStr, "https://api.example.com/users/junit") } func TestServerSpanWithSchemeHostTargetAttributesStable(t *testing.T) { @@ -269,7 +268,7 @@ func TestServerSpanWithSchemeHostTargetAttributesStable(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) + assert.Contains(t, jsonStr, "https://api.example.com/users/junit") } func TestServerSpanWithSchemeServernamePortTargetAttributes(t *testing.T) { @@ -291,7 +290,7 @@ func TestServerSpanWithSchemeServernamePortTargetAttributes(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) + assert.Contains(t, jsonStr, "https://api.example.com/users/junit") } func TestServerSpanWithSchemeServernamePortTargetAttributesStable(t *testing.T) { @@ -313,7 +312,7 @@ func TestServerSpanWithSchemeServernamePortTargetAttributesStable(t *testing.T) require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) + assert.Contains(t, jsonStr, "https://api.example.com/users/junit") } func TestServerSpanWithSchemeNamePortTargetAttributes(t *testing.T) { @@ -337,7 +336,7 @@ func TestServerSpanWithSchemeNamePortTargetAttributes(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "http://kb234.example.com:8080/users/junit")) + assert.Contains(t, jsonStr, "http://kb234.example.com:8080/users/junit") } func TestServerSpanWithSchemeNamePortTargetAttributesStable(t *testing.T) { @@ -361,7 +360,7 @@ func TestServerSpanWithSchemeNamePortTargetAttributesStable(t *testing.T) { require.NoError(t, w.Encode(httpData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "http://kb234.example.com:8080/users/junit")) + assert.Contains(t, jsonStr, "http://kb234.example.com:8080/users/junit") } func TestSpanWithNotEnoughHTTPRequestURLAttributes(t *testing.T) { diff --git a/exporter/awsxrayexporter/internal/translator/segment_test.go b/exporter/awsxrayexporter/internal/translator/segment_test.go index 57ab63ecc726..6351ad99922c 100644 --- a/exporter/awsxrayexporter/internal/translator/segment_test.go +++ b/exporter/awsxrayexporter/internal/translator/segment_test.go @@ -7,7 +7,6 @@ import ( "crypto/rand" "encoding/binary" "fmt" - "strings" "testing" "time" @@ -61,10 +60,10 @@ func TestClientSpanWithRpcAwsSdkClientAttributes(t *testing.T) { assert.NotNil(t, jsonStr) assert.NoError(t, err) - assert.True(t, strings.Contains(jsonStr, "DynamoDB")) - assert.True(t, strings.Contains(jsonStr, "GetItem")) - assert.False(t, strings.Contains(jsonStr, user)) - assert.False(t, strings.Contains(jsonStr, "user")) + assert.Contains(t, jsonStr, "DynamoDB") + assert.Contains(t, jsonStr, "GetItem") + assert.NotContains(t, jsonStr, user) + assert.NotContains(t, jsonStr, "user") } func TestClientSpanWithLegacyAwsSdkClientAttributes(t *testing.T) { @@ -94,10 +93,10 @@ func TestClientSpanWithLegacyAwsSdkClientAttributes(t *testing.T) { assert.NotNil(t, jsonStr) assert.NoError(t, err) - assert.True(t, strings.Contains(jsonStr, "DynamoDB")) - assert.True(t, strings.Contains(jsonStr, "GetItem")) - assert.False(t, strings.Contains(jsonStr, user)) - assert.False(t, strings.Contains(jsonStr, "user")) + assert.Contains(t, jsonStr, "DynamoDB") + assert.Contains(t, jsonStr, "GetItem") + assert.NotContains(t, jsonStr, user) + assert.NotContains(t, jsonStr, "user") } func TestClientSpanWithPeerService(t *testing.T) { @@ -253,8 +252,8 @@ func TestClientSpanWithDbComponent(t *testing.T) { require.NoError(t, w.Encode(segment)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, spanName)) - assert.True(t, strings.Contains(jsonStr, enterpriseAppID)) + assert.Contains(t, jsonStr, spanName) + assert.Contains(t, jsonStr, enterpriseAppID) } func TestClientSpanWithHttpHost(t *testing.T) { @@ -376,9 +375,9 @@ func TestSpanWithInvalidTraceIdWithoutTimestampValidation(t *testing.T) { require.NoError(t, err) assert.NotNil(t, jsonStr) - assert.True(t, strings.Contains(jsonStr, "ProducerService")) - assert.False(t, strings.Contains(jsonStr, user)) - assert.False(t, strings.Contains(jsonStr, "user")) + assert.Contains(t, jsonStr, "ProducerService") + assert.NotContains(t, jsonStr, user) + assert.NotContains(t, jsonStr, "user") } func TestSpanWithExpiredTraceIdWithoutTimestampValidation(t *testing.T) { @@ -1088,9 +1087,9 @@ func TestClientSpanWithAwsRemoteServiceName(t *testing.T) { assert.NotNil(t, jsonStr) assert.NoError(t, err) - assert.True(t, strings.Contains(jsonStr, "PaymentService")) - assert.False(t, strings.Contains(jsonStr, user)) - assert.False(t, strings.Contains(jsonStr, "user")) + assert.Contains(t, jsonStr, "PaymentService") + assert.NotContains(t, jsonStr, user) + assert.NotContains(t, jsonStr, "user") } func TestAwsSdkSpanWithDeprecatedAwsRemoteServiceName(t *testing.T) { @@ -1115,10 +1114,10 @@ func TestAwsSdkSpanWithDeprecatedAwsRemoteServiceName(t *testing.T) { assert.NotNil(t, jsonStr) assert.NoError(t, err) - assert.True(t, strings.Contains(jsonStr, "DynamoDb")) - assert.False(t, strings.Contains(jsonStr, "DynamoDb.PutItem")) - assert.False(t, strings.Contains(jsonStr, user)) - assert.False(t, strings.Contains(jsonStr, "user")) + assert.Contains(t, jsonStr, "DynamoDb") + assert.NotContains(t, jsonStr, "DynamoDb.PutItem") + assert.NotContains(t, jsonStr, user) + assert.NotContains(t, jsonStr, "user") } func TestAwsSdkSpanWithAwsRemoteServiceName(t *testing.T) { @@ -1143,10 +1142,10 @@ func TestAwsSdkSpanWithAwsRemoteServiceName(t *testing.T) { assert.NotNil(t, jsonStr) assert.NoError(t, err) - assert.True(t, strings.Contains(jsonStr, "DynamoDb")) - assert.False(t, strings.Contains(jsonStr, "DynamoDb.PutItem")) - assert.False(t, strings.Contains(jsonStr, user)) - assert.False(t, strings.Contains(jsonStr, "user")) + assert.Contains(t, jsonStr, "DynamoDb") + assert.NotContains(t, jsonStr, "DynamoDb.PutItem") + assert.NotContains(t, jsonStr, user) + assert.NotContains(t, jsonStr, "user") } func TestProducerSpanWithAwsRemoteServiceName(t *testing.T) { @@ -1172,9 +1171,9 @@ func TestProducerSpanWithAwsRemoteServiceName(t *testing.T) { assert.NotNil(t, jsonStr) assert.NoError(t, err) - assert.True(t, strings.Contains(jsonStr, "ProducerService")) - assert.False(t, strings.Contains(jsonStr, user)) - assert.False(t, strings.Contains(jsonStr, "user")) + assert.Contains(t, jsonStr, "ProducerService") + assert.NotContains(t, jsonStr, user) + assert.NotContains(t, jsonStr, "user") } func TestConsumerSpanWithAwsRemoteServiceName(t *testing.T) { @@ -1191,9 +1190,9 @@ func TestConsumerSpanWithAwsRemoteServiceName(t *testing.T) { assert.NotNil(t, jsonStr) assert.NoError(t, err) - assert.True(t, strings.Contains(jsonStr, "ConsumerService")) - assert.False(t, strings.Contains(jsonStr, user)) - assert.False(t, strings.Contains(jsonStr, "user")) + assert.Contains(t, jsonStr, "ConsumerService") + assert.NotContains(t, jsonStr, user) + assert.NotContains(t, jsonStr, "user") } func TestServerSpanWithAwsLocalServiceName(t *testing.T) { @@ -1219,9 +1218,9 @@ func TestServerSpanWithAwsLocalServiceName(t *testing.T) { assert.NotNil(t, jsonStr) assert.NoError(t, err) - assert.True(t, strings.Contains(jsonStr, "PaymentLocalService")) - assert.False(t, strings.Contains(jsonStr, user)) - assert.False(t, strings.Contains(jsonStr, "user")) + assert.Contains(t, jsonStr, "PaymentLocalService") + assert.NotContains(t, jsonStr, user) + assert.NotContains(t, jsonStr, "user") } func validateLocalRootDependencySubsegment(t *testing.T, segment *awsxray.Segment, span ptrace.Span, parentID string) { diff --git a/exporter/awsxrayexporter/internal/translator/service_test.go b/exporter/awsxrayexporter/internal/translator/service_test.go index 9d26c5f2f098..81745b031aba 100644 --- a/exporter/awsxrayexporter/internal/translator/service_test.go +++ b/exporter/awsxrayexporter/internal/translator/service_test.go @@ -4,7 +4,6 @@ package translator import ( - "strings" "testing" "github.com/stretchr/testify/assert" @@ -23,7 +22,7 @@ func TestServiceFromResource(t *testing.T) { require.NoError(t, w.Encode(service)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "semver:1.1.4")) + assert.Contains(t, jsonStr, "semver:1.1.4") } func TestServiceFromResourceWithNoServiceVersion(t *testing.T) { @@ -36,7 +35,7 @@ func TestServiceFromResourceWithNoServiceVersion(t *testing.T) { require.NoError(t, w.Encode(service)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "v1")) + assert.Contains(t, jsonStr, "v1") } func TestServiceFromNullResource(t *testing.T) { diff --git a/exporter/awsxrayexporter/internal/translator/span_links_test.go b/exporter/awsxrayexporter/internal/translator/span_links_test.go index 1c70f1c75009..6c1fb6107bf8 100644 --- a/exporter/awsxrayexporter/internal/translator/span_links_test.go +++ b/exporter/awsxrayexporter/internal/translator/span_links_test.go @@ -5,7 +5,6 @@ package translator // import "github.com/open-telemetry/opentelemetry-collector- import ( "encoding/binary" - "strings" "testing" "time" @@ -37,10 +36,10 @@ func TestSpanLinkSimple(t *testing.T) { jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil, false) - assert.True(t, strings.Contains(jsonStr, "links")) - assert.False(t, strings.Contains(jsonStr, "attributes")) - assert.True(t, strings.Contains(jsonStr, convertedTraceID)) - assert.True(t, strings.Contains(jsonStr, spanLink.SpanID().String())) + assert.Contains(t, jsonStr, "links") + assert.NotContains(t, jsonStr, "attributes") + assert.Contains(t, jsonStr, convertedTraceID) + assert.Contains(t, jsonStr, spanLink.SpanID().String()) } func TestSpanLinkEmpty(t *testing.T) { @@ -56,7 +55,7 @@ func TestSpanLinkEmpty(t *testing.T) { jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil, false) - assert.False(t, strings.Contains(jsonStr, "links")) + assert.NotContains(t, jsonStr, "links") } func TestOldSpanLinkError(t *testing.T) { @@ -125,14 +124,14 @@ func TestTwoSpanLinks(t *testing.T) { jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil, false) - assert.True(t, strings.Contains(jsonStr, "attributes")) - assert.True(t, strings.Contains(jsonStr, "links")) - assert.True(t, strings.Contains(jsonStr, "myKey1")) - assert.True(t, strings.Contains(jsonStr, "myKey2")) - assert.True(t, strings.Contains(jsonStr, "ABC")) - assert.True(t, strings.Contains(jsonStr, "1234")) - assert.True(t, strings.Contains(jsonStr, convertedTraceID1)) - assert.True(t, strings.Contains(jsonStr, convertedTraceID2)) + assert.Contains(t, jsonStr, "attributes") + assert.Contains(t, jsonStr, "links") + assert.Contains(t, jsonStr, "myKey1") + assert.Contains(t, jsonStr, "myKey2") + assert.Contains(t, jsonStr, "ABC") + assert.Contains(t, jsonStr, "1234") + assert.Contains(t, jsonStr, convertedTraceID1) + assert.Contains(t, jsonStr, convertedTraceID2) } func TestSpanLinkComplexAttributes(t *testing.T) { @@ -198,34 +197,34 @@ func TestSpanLinkComplexAttributes(t *testing.T) { jsonStr, _ := MakeSegmentDocumentString(span, resource, nil, false, nil, false) - assert.True(t, strings.Contains(jsonStr, "links")) + assert.Contains(t, jsonStr, "links") - assert.True(t, strings.Contains(jsonStr, "myKey1")) - assert.True(t, strings.Contains(jsonStr, "myValue")) + assert.Contains(t, jsonStr, "myKey1") + assert.Contains(t, jsonStr, "myValue") - assert.True(t, strings.Contains(jsonStr, "myKey2")) - assert.True(t, strings.Contains(jsonStr, "true")) + assert.Contains(t, jsonStr, "myKey2") + assert.Contains(t, jsonStr, "true") - assert.True(t, strings.Contains(jsonStr, "myKey3")) - assert.True(t, strings.Contains(jsonStr, "112233")) + assert.Contains(t, jsonStr, "myKey3") + assert.Contains(t, jsonStr, "112233") - assert.True(t, strings.Contains(jsonStr, "myKey4")) - assert.True(t, strings.Contains(jsonStr, "3.1415")) + assert.Contains(t, jsonStr, "myKey4") + assert.Contains(t, jsonStr, "3.1415") - assert.True(t, strings.Contains(jsonStr, "myKey5")) - assert.True(t, strings.Contains(jsonStr, "apple")) - assert.True(t, strings.Contains(jsonStr, "pear")) - assert.True(t, strings.Contains(jsonStr, "banana")) + assert.Contains(t, jsonStr, "myKey5") + assert.Contains(t, jsonStr, "apple") + assert.Contains(t, jsonStr, "pear") + assert.Contains(t, jsonStr, "banana") - assert.True(t, strings.Contains(jsonStr, "myKey6")) - assert.True(t, strings.Contains(jsonStr, "false")) + assert.Contains(t, jsonStr, "myKey6") + assert.Contains(t, jsonStr, "false") - assert.True(t, strings.Contains(jsonStr, "myKey7")) - assert.True(t, strings.Contains(jsonStr, "1234")) - assert.True(t, strings.Contains(jsonStr, "5678")) - assert.True(t, strings.Contains(jsonStr, "9012")) + assert.Contains(t, jsonStr, "myKey7") + assert.Contains(t, jsonStr, "1234") + assert.Contains(t, jsonStr, "5678") + assert.Contains(t, jsonStr, "9012") - assert.True(t, strings.Contains(jsonStr, "myKey8")) - assert.True(t, strings.Contains(jsonStr, "2.718")) - assert.True(t, strings.Contains(jsonStr, "1.618")) + assert.Contains(t, jsonStr, "myKey8") + assert.Contains(t, jsonStr, "2.718") + assert.Contains(t, jsonStr, "1.618") } diff --git a/exporter/awsxrayexporter/internal/translator/sql_test.go b/exporter/awsxrayexporter/internal/translator/sql_test.go index c15ecc639d87..cba2222b64d7 100644 --- a/exporter/awsxrayexporter/internal/translator/sql_test.go +++ b/exporter/awsxrayexporter/internal/translator/sql_test.go @@ -4,7 +4,6 @@ package translator import ( - "strings" "testing" "time" @@ -35,7 +34,7 @@ func TestClientSpanWithStatementAttribute(t *testing.T) { require.NoError(t, w.Encode(sqlData)) jsonStr := w.String() testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "mysql://db.example.com:3306/customers")) + assert.Contains(t, jsonStr, "mysql://db.example.com:3306/customers") } func TestClientSpanWithNonSQLDatabase(t *testing.T) { diff --git a/exporter/elasticsearchexporter/exporter_test.go b/exporter/elasticsearchexporter/exporter_test.go index 9a9b86a5be6f..32584fd7f8a6 100644 --- a/exporter/elasticsearchexporter/exporter_test.go +++ b/exporter/elasticsearchexporter/exporter_test.go @@ -233,7 +233,7 @@ func TestExporterLogs(t *testing.T) { t.Run("publish with dedup", func(t *testing.T) { rec := newBulkRecorder() server := newESTestServer(t, func(docs []itemRequest) ([]itemResponse, error) { - assert.Equal(t, `{"@timestamp":"1970-01-01T00:00:00.000000000Z","Scope":{"name":"","value":"value","version":""},"SeverityNumber":0,"TraceFlags":0}`, string(docs[0].Document)) + assert.JSONEq(t, `{"@timestamp":"1970-01-01T00:00:00.000000000Z","Scope":{"name":"","value":"value","version":""},"SeverityNumber":0,"TraceFlags":0}`, string(docs[0].Document)) rec.Record(docs) return itemsAllOK(docs) }) @@ -706,9 +706,9 @@ func TestExporterLogs(t *testing.T) { assert.Len(t, rec.Items(), 1) doc := rec.Items()[0].Document - assert.Equal(t, `{"some.record.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `attributes`).Raw) - assert.Equal(t, `{"some.scope.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `scope.attributes`).Raw) - assert.Equal(t, `{"some.resource.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `resource.attributes`).Raw) + assert.JSONEq(t, `{"some.record.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `attributes`).Raw) + assert.JSONEq(t, `{"some.scope.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `scope.attributes`).Raw) + assert.JSONEq(t, `{"some.resource.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `resource.attributes`).Raw) }) t.Run("otel mode attribute key prefix conflict", func(t *testing.T) { @@ -1223,9 +1223,9 @@ func TestExporterMetrics(t *testing.T) { assert.Len(t, rec.Items(), 1) doc := rec.Items()[0].Document - assert.Equal(t, `{"some.record.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `attributes`).Raw) - assert.Equal(t, `{"some.scope.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `scope.attributes`).Raw) - assert.Equal(t, `{"some.resource.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `resource.attributes`).Raw) + assert.JSONEq(t, `{"some.record.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `attributes`).Raw) + assert.JSONEq(t, `{"some.scope.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `scope.attributes`).Raw) + assert.JSONEq(t, `{"some.resource.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `resource.attributes`).Raw) }) t.Run("otel mode _doc_count hint", func(t *testing.T) { @@ -1689,9 +1689,9 @@ func TestExporterTraces(t *testing.T) { assert.Len(t, rec.Items(), 2) for _, item := range rec.Items() { doc := item.Document - assert.Equal(t, `{"some.record.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `attributes`).Raw) - assert.Equal(t, `{"some.scope.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `scope.attributes`).Raw) - assert.Equal(t, `{"some.resource.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `resource.attributes`).Raw) + assert.JSONEq(t, `{"some.record.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `attributes`).Raw) + assert.JSONEq(t, `{"some.scope.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `scope.attributes`).Raw) + assert.JSONEq(t, `{"some.resource.attribute":["foo","bar"]}`, gjson.GetBytes(doc, `resource.attributes`).Raw) } }) diff --git a/exporter/honeycombmarkerexporter/logs_exporter_test.go b/exporter/honeycombmarkerexporter/logs_exporter_test.go index 3eceacedaf4d..05f2e8c61f46 100644 --- a/exporter/honeycombmarkerexporter/logs_exporter_test.go +++ b/exporter/honeycombmarkerexporter/logs_exporter_test.go @@ -8,7 +8,6 @@ import ( "encoding/json" "net/http" "net/http/httptest" - "strings" "testing" "github.com/stretchr/testify/assert" @@ -138,7 +137,7 @@ func TestExportMarkers(t *testing.T) { userAgent := req.Header.Get(userAgentHeaderKey) assert.NotEmpty(t, userAgent) - assert.True(t, strings.Contains(userAgent, "OpenTelemetry Collector")) + assert.Contains(t, userAgent, "OpenTelemetry Collector") rw.WriteHeader(http.StatusAccepted) })) diff --git a/exporter/mezmoexporter/exporter_test.go b/exporter/mezmoexporter/exporter_test.go index 885dee55756d..868cdf8153bf 100644 --- a/exporter/mezmoexporter/exporter_test.go +++ b/exporter/mezmoexporter/exporter_test.go @@ -268,5 +268,5 @@ func Test404IngestError(t *testing.T) { responseField := logLine.Context[0] assert.Equal(t, "response", responseField.Key) - assert.Equal(t, `{"foo":"bar"}`, responseField.String) + assert.JSONEq(t, `{"foo":"bar"}`, responseField.String) } diff --git a/exporter/pulsarexporter/jaeger_marshaler_test.go b/exporter/pulsarexporter/jaeger_marshaler_test.go index 8b0eb9bec1ca..4df974bac0f2 100644 --- a/exporter/pulsarexporter/jaeger_marshaler_test.go +++ b/exporter/pulsarexporter/jaeger_marshaler_test.go @@ -42,7 +42,7 @@ func TestJaegerJsonBatchMarshaler(t *testing.T) { } jaegerJSONMessages, err := jaegerJSONMarshaler.Marshal(ptraces, "") require.NoError(t, err) - assert.Equal(t, jaegerJSONMessages[0].Payload, jsonBytes) + assert.JSONEq(t, string(jaegerJSONMessages[0].Payload), string(jsonBytes)) } func TestJaegerProtoBatchMarshaler(t *testing.T) { diff --git a/exporter/pulsarexporter/marshaler_test.go b/exporter/pulsarexporter/marshaler_test.go index b82e5531cae4..d84f69c89e02 100644 --- a/exporter/pulsarexporter/marshaler_test.go +++ b/exporter/pulsarexporter/marshaler_test.go @@ -102,7 +102,7 @@ func TestOTLPTracesJsonMarshaling(t *testing.T) { // Since marshaling json is not guaranteed to be in order // within a string, using a map to compare that the expected values are there - expectedJSON := map[string]any{ + expectedMap := map[string]any{ "resourceSpans": []any{ map[string]any{ "resource": map[string]any{}, @@ -133,5 +133,5 @@ func TestOTLPTracesJsonMarshaling(t *testing.T) { err = json.Unmarshal(payload, &final) require.NoError(t, err, "Must not error marshaling expected data") - assert.Equal(t, expectedJSON, final, "Must match the expected value") + assert.Equal(t, expectedMap, final, "Must match the expected value") } diff --git a/exporter/splunkhecexporter/metricdata_to_splunk_test.go b/exporter/splunkhecexporter/metricdata_to_splunk_test.go index a2ea1bb718d3..b15d5e840b0c 100644 --- a/exporter/splunkhecexporter/metricdata_to_splunk_test.go +++ b/exporter/splunkhecexporter/metricdata_to_splunk_test.go @@ -716,7 +716,7 @@ func TestMergeEvents(t *testing.T) { require.Len(t, merged, 1) b, err := json.Marshal(merged[0]) require.NoError(t, err) - require.Equal(t, `{"host":"","event":"metric","fields":{"IF-Azure":"azure-env","k8s.cluster.name":"devops-uat","k8s.namespace.name":"splunk-collector-tests","k8s.node.name":"myk8snodename","k8s.pod.name":"my-otel-collector-pod","metric_name:otel.collector.test":3411,"metric_name:otel.collector.test2":26059,"metric_type":"Gauge","metricsIndex":"test_metrics","metricsPlatform":"unset","resourceAttrs":"NO","testNumber":"number42","testRun":"42"}}`, string(b)) + require.JSONEq(t, `{"host":"","event":"metric","fields":{"IF-Azure":"azure-env","k8s.cluster.name":"devops-uat","k8s.namespace.name":"splunk-collector-tests","k8s.node.name":"myk8snodename","k8s.pod.name":"my-otel-collector-pod","metric_name:otel.collector.test":3411,"metric_name:otel.collector.test2":26059,"metric_type":"Gauge","metricsIndex":"test_metrics","metricsPlatform":"unset","resourceAttrs":"NO","testNumber":"number42","testRun":"42"}}`, string(b)) } func newMetricsWithResources() pcommon.Resource { diff --git a/exporter/syslogexporter/rfc5424_formatter_test.go b/exporter/syslogexporter/rfc5424_formatter_test.go index 3c6f48cd8ee7..edf4e157ffc8 100644 --- a/exporter/syslogexporter/rfc5424_formatter_test.go +++ b/exporter/syslogexporter/rfc5424_formatter_test.go @@ -6,7 +6,6 @@ package syslogexporter import ( "fmt" "regexp" - "strings" "testing" "time" @@ -81,10 +80,10 @@ func TestRFC5424Formatter(t *testing.T) { matched, err := regexp.MatchString(expectedRegex, actual) assert.NoError(t, err) assert.Truef(t, matched, "unexpected form of formatted message, formatted message: %s, regexp: %s", actual, expectedRegex) - assert.True(t, strings.Contains(actual, "Realm=\"SecureAuth0\"")) - assert.True(t, strings.Contains(actual, "UserHostAddress=\"192.168.2.132\"")) - assert.True(t, strings.Contains(actual, "UserID=\"Tester2\"")) - assert.True(t, strings.Contains(actual, "PEN=\"27389\"")) + assert.Contains(t, actual, "Realm=\"SecureAuth0\"") + assert.Contains(t, actual, "UserHostAddress=\"192.168.2.132\"") + assert.Contains(t, actual, "UserID=\"Tester2\"") + assert.Contains(t, actual, "PEN=\"27389\"") // Test defaults expected = "<165>1 2003-08-24T12:14:15.000003Z - - - - -\n" diff --git a/extension/encoding/avrologencodingextension/extension_test.go b/extension/encoding/avrologencodingextension/extension_test.go index c8b44021dc47..b66f12fbd9b0 100644 --- a/extension/encoding/avrologencodingextension/extension_test.go +++ b/extension/encoding/avrologencodingextension/extension_test.go @@ -34,7 +34,7 @@ func TestUnmarshal(t *testing.T) { logRecord := logs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.NoError(t, err) - assert.Equal(t, "{\"count\":5,\"hostname\":\"host1\",\"level\":\"warn\",\"levelEnum\":\"INFO\",\"mapField\":{},\"message\":\"log message\",\"nestedRecord\":{\"field1\":12,\"field2\":\"val2\"},\"properties\":[\"prop1\",\"prop2\"],\"severity\":1,\"timestamp\":1697187201488000000}", logRecord.Body().AsString()) + assert.JSONEq(t, "{\"count\":5,\"hostname\":\"host1\",\"level\":\"warn\",\"levelEnum\":\"INFO\",\"mapField\":{},\"message\":\"log message\",\"nestedRecord\":{\"field1\":12,\"field2\":\"val2\"},\"properties\":[\"prop1\",\"prop2\"],\"severity\":1,\"timestamp\":1697187201488000000}", logRecord.Body().AsString()) } func TestInvalidUnmarshal(t *testing.T) { diff --git a/extension/encoding/jsonlogencodingextension/json_test.go b/extension/encoding/jsonlogencodingextension/json_test.go index 2fcfa3d13129..afb77d24f5b4 100644 --- a/extension/encoding/jsonlogencodingextension/json_test.go +++ b/extension/encoding/jsonlogencodingextension/json_test.go @@ -25,7 +25,7 @@ func TestMarshalUnmarshal(t *testing.T) { buf, err := e.MarshalLogs(ld) assert.NoError(t, err) assert.NotEmpty(t, buf) - assert.Equal(t, json, string(buf)) + assert.JSONEq(t, json, string(buf)) } func TestInvalidMarshal(t *testing.T) { @@ -59,7 +59,7 @@ func TestPrettyLogProcessor(t *testing.T) { lp, err := j.logProcessor(sampleLog()) assert.NoError(t, err) assert.NotNil(t, lp) - assert.Equal(t, `[{"body":{"log":"test"},"logAttributes":{"foo":"bar"},"resourceAttributes":{"test":"logs-test"}},{"body":"log testing","resourceAttributes":{"test":"logs-test"}}]`, string(lp)) + assert.JSONEq(t, `[{"body":{"log":"test"},"logAttributes":{"foo":"bar"},"resourceAttributes":{"test":"logs-test"}},{"body":"log testing","resourceAttributes":{"test":"logs-test"}}]`, string(lp)) } func sampleLog() plog.Logs { diff --git a/extension/healthcheckextension/integration_test.go b/extension/healthcheckextension/integration_test.go index af8756b50892..ba765f569ab7 100644 --- a/extension/healthcheckextension/integration_test.go +++ b/extension/healthcheckextension/integration_test.go @@ -37,7 +37,7 @@ func Test_SimpleHealthCheck(t *testing.T) { var buf bytes.Buffer _, err = io.Copy(&buf, resp.Body) require.NoError(t, err) - assert.Equal(t, `{"status":"Server not available","upSince":"0001-01-01T00:00:00Z","uptime":""}`, buf.String()) + assert.JSONEq(t, `{"status":"Server not available","upSince":"0001-01-01T00:00:00Z","uptime":""}`, buf.String()) err = e.(*healthCheckExtension).Ready() require.NoError(t, err) resp, err = http.DefaultClient.Get(fmt.Sprintf("http://localhost:%d/", port)) diff --git a/extension/healthcheckv2extension/extension_test.go b/extension/healthcheckv2extension/extension_test.go index c15acc269245..57ba700e7e31 100644 --- a/extension/healthcheckv2extension/extension_test.go +++ b/extension/healthcheckv2extension/extension_test.go @@ -131,5 +131,5 @@ func TestNotifyConfig(t *testing.T) { body, err := io.ReadAll(resp.Body) require.NoError(t, err) - assert.Equal(t, confJSON, body) + assert.JSONEq(t, string(confJSON), string(body)) } diff --git a/extension/healthcheckv2extension/internal/http/server_test.go b/extension/healthcheckv2extension/internal/http/server_test.go index 4a11d0138d55..de365258206e 100644 --- a/extension/healthcheckv2extension/internal/http/server_test.go +++ b/extension/healthcheckv2extension/internal/http/server_test.go @@ -2986,7 +2986,7 @@ func TestStatus(t *testing.T) { body, err := io.ReadAll(resp.Body) require.NoError(t, err) - assert.True(t, strings.Contains(string(body), ts.expectedBody)) + assert.Contains(t, string(body), ts.expectedBody) if ts.expectedComponentStatus != nil { st := &serializableStatus{} diff --git a/extension/httpforwarderextension/extension_test.go b/extension/httpforwarderextension/extension_test.go index 7e3563bf6fe8..f5acd26cbe30 100644 --- a/extension/httpforwarderextension/extension_test.go +++ b/extension/httpforwarderextension/extension_test.go @@ -205,7 +205,7 @@ func TestExtension(t *testing.T) { if test.startUpError { err = hf.Start(ctx, componenttest.NewNopHost()) if test.startUpErrorMessage != "" { - require.True(t, strings.Contains(err.Error(), test.startUpErrorMessage)) + require.Contains(t, err.Error(), test.startUpErrorMessage) } require.Error(t, err) diff --git a/extension/httpforwarderextension/factory_test.go b/extension/httpforwarderextension/factory_test.go index 74824c3ab0ad..f515c94cdb47 100644 --- a/extension/httpforwarderextension/factory_test.go +++ b/extension/httpforwarderextension/factory_test.go @@ -5,7 +5,6 @@ package httpforwarderextension import ( "context" - "strings" "testing" "time" @@ -57,7 +56,7 @@ func TestFactory(t *testing.T) { ) if test.wantErr { if test.wantErrMessage != "" { - require.True(t, strings.Contains(err.Error(), test.wantErrMessage)) + require.Contains(t, err.Error(), test.wantErrMessage) } require.Error(t, err) require.Nil(t, e) diff --git a/extension/jaegerremotesampling/internal/http_test.go b/extension/jaegerremotesampling/internal/http_test.go index 0ad7a113e9a5..075073d82215 100644 --- a/extension/jaegerremotesampling/internal/http_test.go +++ b/extension/jaegerremotesampling/internal/http_test.go @@ -80,7 +80,7 @@ func TestEndpointsAreWired(t *testing.T) { resp.Body.Close() body := string(samplingStrategiesBytes) - assert.Equal(t, `{"probabilisticSampling":{"samplingRate":1}}`, body) + assert.JSONEq(t, `{"probabilisticSampling":{"samplingRate":1}}`, body) }) } } diff --git a/internal/tools/go.mod b/internal/tools/go.mod index 373c22ae3427..84ff19abb0e5 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -1,9 +1,11 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/tools -go 1.22.0 +go 1.22.1 + +toolchain go1.22.8 require ( - github.com/Antonboom/testifylint v1.4.3 + github.com/Antonboom/testifylint v1.5.0 github.com/Khan/genqlient v0.7.0 github.com/client9/misspell v0.3.4 github.com/daixiang0/gci v0.13.5 diff --git a/internal/tools/go.sum b/internal/tools/go.sum index ff9fceffcdc2..b9dc248f5aab 100644 --- a/internal/tools/go.sum +++ b/internal/tools/go.sum @@ -12,8 +12,8 @@ github.com/Antonboom/errname v0.1.13 h1:JHICqsewj/fNckzrfVSe+T33svwQxmjC+1ntDsHO github.com/Antonboom/errname v0.1.13/go.mod h1:uWyefRYRN54lBg6HseYCFhs6Qjcy41Y3Jl/dVhA87Ns= github.com/Antonboom/nilnil v0.1.9 h1:eKFMejSxPSA9eLSensFmjW2XTgTwJMjZ8hUHtV4s/SQ= github.com/Antonboom/nilnil v0.1.9/go.mod h1:iGe2rYwCq5/Me1khrysB4nwI7swQvjclR8/YRPl5ihQ= -github.com/Antonboom/testifylint v1.4.3 h1:ohMt6AHuHgttaQ1xb6SSnxCeK4/rnK7KKzbvs7DmEck= -github.com/Antonboom/testifylint v1.4.3/go.mod h1:+8Q9+AOLsz5ZiQiiYujJKs9mNz398+M6UgslP4qgJLA= +github.com/Antonboom/testifylint v1.5.0 h1:dlUIsDMtCrZWUnvkaCz3quJCoIjaGi41GzjPBGkkJ8A= +github.com/Antonboom/testifylint v1.5.0/go.mod h1:wqaJbu0Blb5Wag2wv7Z5xt+CIV+eVLxtGZrlK13z3AE= github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/Crocmagnon/fatcontext v0.2.2 h1:OrFlsDdOj9hW/oBEJBNSuH7QWf+E9WPVHw+x52bXVbk= diff --git a/pkg/stanza/operator/operatortest/confmap.go b/pkg/stanza/operator/operatortest/confmap.go index 90486dd435e5..dc237dfaa6ce 100644 --- a/pkg/stanza/operator/operatortest/confmap.go +++ b/pkg/stanza/operator/operatortest/confmap.go @@ -4,7 +4,6 @@ package operatortest // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/operatortest" import ( - "fmt" "testing" "github.com/stretchr/testify/require" @@ -37,7 +36,7 @@ func (c ConfigUnmarshalTests) Run(t *testing.T) { t.Run(tc.Name, func(t *testing.T) { testConfMap, err := testConfMaps.Sub(tc.Name) require.NoError(t, err) - require.NotEmpty(t, testConfMap.AllKeys(), fmt.Sprintf("config not found: '%s'", tc.Name)) + require.NotEmpty(t, testConfMap.AllKeys(), "config not found: '%s'", tc.Name) cfg := newAnyOpConfig(c.DefaultConfig) err = testConfMap.Unmarshal(cfg) diff --git a/processor/remotetapprocessor/server_test.go b/processor/remotetapprocessor/server_test.go index aa27991ff900..8a6b68397e0f 100644 --- a/processor/remotetapprocessor/server_test.go +++ b/processor/remotetapprocessor/server_test.go @@ -50,7 +50,7 @@ func TestSocketConnectionLogs(t *testing.T) { n, _ := wsConn.Read(buf) return n == 132 }, 1*time.Second, 100*time.Millisecond, "received message") - require.Equal(t, `{"resourceLogs":[{"resource":{},"scopeLogs":[{"scope":{},"logRecords":[{"body":{"stringValue":"foo"},"traceId":"","spanId":""}]}]}]}`, string(buf[0:132])) + require.JSONEq(t, `{"resourceLogs":[{"resource":{},"scopeLogs":[{"scope":{},"logRecords":[{"body":{"stringValue":"foo"},"traceId":"","spanId":""}]}]}]}`, string(buf[0:132])) err = processor.Shutdown(context.Background()) require.NoError(t, err) @@ -86,7 +86,7 @@ func TestSocketConnectionMetrics(t *testing.T) { n, _ := wsConn.Read(buf) return n == 94 }, 1*time.Second, 100*time.Millisecond, "received message") - require.Equal(t, `{"resourceMetrics":[{"resource":{},"scopeMetrics":[{"scope":{},"metrics":[{"name":"foo"}]}]}]}`, string(buf[0:94])) + require.JSONEq(t, `{"resourceMetrics":[{"resource":{},"scopeMetrics":[{"scope":{},"metrics":[{"name":"foo"}]}]}]}`, string(buf[0:94])) err = processor.Shutdown(context.Background()) require.NoError(t, err) @@ -122,7 +122,7 @@ func TestSocketConnectionTraces(t *testing.T) { n, _ := wsConn.Read(buf) return n == 143 }, 1*time.Second, 100*time.Millisecond, "received message") - require.Equal(t, `{"resourceSpans":[{"resource":{},"scopeSpans":[{"scope":{},"spans":[{"traceId":"","spanId":"","parentSpanId":"","name":"foo","status":{}}]}]}]}`, string(buf[0:143])) + require.JSONEq(t, `{"resourceSpans":[{"resource":{},"scopeSpans":[{"scope":{},"spans":[{"traceId":"","spanId":"","parentSpanId":"","name":"foo","status":{}}]}]}]}`, string(buf[0:143])) err = processor.Shutdown(context.Background()) require.NoError(t, err) diff --git a/processor/tailsamplingprocessor/internal/cache/lru_cache_test.go b/processor/tailsamplingprocessor/internal/cache/lru_cache_test.go index 36627bed0e87..b0f86e1c46a5 100644 --- a/processor/tailsamplingprocessor/internal/cache/lru_cache_test.go +++ b/processor/tailsamplingprocessor/internal/cache/lru_cache_test.go @@ -61,8 +61,8 @@ func TestLeastRecentlyUsedIsEvicted(t *testing.T) { c.Put(id1, true) c.Put(id2, true) v, ok := c.Get(id1) // use id1 - assert.True(t, true, v) - assert.True(t, true, ok) + assert.True(t, v) + assert.True(t, ok) c.Put(id3, true) v, ok = c.Get(id1) diff --git a/processor/transformprocessor/internal/metrics/func_convert_exponential_hist_to_explicit_hist_test.go b/processor/transformprocessor/internal/metrics/func_convert_exponential_hist_to_explicit_hist_test.go index 8d5d6ec8aa3c..f61969b17c18 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_exponential_hist_to_explicit_hist_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_exponential_hist_to_explicit_hist_test.go @@ -4,7 +4,6 @@ package metrics import ( - "strings" "testing" "time" @@ -782,7 +781,7 @@ func Test_convertExponentialHistToExplicitHist_validate(t *testing.T) { t.Run(tt.name, func(t *testing.T) { _, err := convertExponentialHistToExplicitHist("random", tt.sliceExplicitBoundsArgs) assert.Error(t, err) - assert.True(t, strings.Contains(err.Error(), "explicit bounds cannot be empty")) + assert.Contains(t, err.Error(), "explicit bounds cannot be empty") }) } } diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/handlecount/handles_windows_test.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/handlecount/handles_windows_test.go index 9ce32bf51e51..b757c83404bb 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/handlecount/handles_windows_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/handlecount/handles_windows_test.go @@ -7,7 +7,6 @@ package handlecount import ( "errors" - "strings" "testing" "github.com/stretchr/testify/assert" @@ -33,7 +32,7 @@ func TestHandleCountManager(t *testing.T) { _, err = m.GetProcessHandleCount(3) assert.ErrorIs(t, errors.Unwrap(err), ErrNoHandleCountForProcess) - assert.True(t, strings.Contains(err.Error(), "3")) + assert.Contains(t, err.Error(), "3") } type mockQueryer struct { diff --git a/receiver/splunkhecreceiver/receiver_test.go b/receiver/splunkhecreceiver/receiver_test.go index 3c7351aedd0e..f45b3ee2e011 100644 --- a/receiver/splunkhecreceiver/receiver_test.go +++ b/receiver/splunkhecreceiver/receiver_test.go @@ -41,14 +41,14 @@ import ( func assertHecSuccessResponse(t *testing.T, resp *http.Response, body any) { status := resp.StatusCode assert.Equal(t, http.StatusOK, status) - assert.Equal(t, httpJSONTypeHeader, resp.Header.Get(httpContentTypeHeader)) + assert.Equal(t, "application/json", resp.Header.Get(httpContentTypeHeader)) assert.Equal(t, map[string]any{"code": float64(0), "text": "Success"}, body) } func assertHecSuccessResponseWithAckID(t *testing.T, resp *http.Response, body any, ackID uint64) { status := resp.StatusCode assert.Equal(t, http.StatusOK, status) - assert.Equal(t, httpJSONTypeHeader, resp.Header.Get(httpContentTypeHeader)) + assert.Equal(t, "application/json", resp.Header.Get(httpContentTypeHeader)) assert.Equal(t, map[string]any{"code": float64(0), "text": "Success", "ackId": float64(ackID)}, body) } @@ -1768,7 +1768,7 @@ func Test_splunkhecreceiver_handleHealthPath(t *testing.T) { respBytes, err := io.ReadAll(resp.Body) assert.NoError(t, err) defer resp.Body.Close() - assert.Equal(t, responseHecHealthy, string(respBytes)) + assert.JSONEq(t, responseHecHealthy, string(respBytes)) assert.Equal(t, 200, resp.StatusCode) } @@ -1837,7 +1837,7 @@ func Test_splunkhecreceiver_handle_nested_fields(t *testing.T) { assert.Equal(t, 1, sink.LogRecordCount()) } else { assert.Equal(t, http.StatusBadRequest, w.Code) - assert.Equal(t, fmt.Sprintf(responseErrHandlingIndexedFields, 0), w.Body.String()) + assert.JSONEq(t, fmt.Sprintf(responseErrHandlingIndexedFields, 0), w.Body.String()) } }) @@ -1861,7 +1861,7 @@ func Test_splunkhecReceiver_rawReqHasmetadataInResource(t *testing.T) { assertResponse := func(t *testing.T, status int, body string) { assert.Equal(t, http.StatusOK, status) - assert.Equal(t, responseOK, body) + assert.JSONEq(t, responseOK, body) } tests := []struct { @@ -2012,7 +2012,7 @@ func Test_splunkhecReceiver_healthCheck_success(t *testing.T) { }(), assertResponse: func(t *testing.T, status int, body string) { assert.Equal(t, http.StatusOK, status) - assert.Equal(t, responseHecHealthy, body) + assert.JSONEq(t, responseHecHealthy, body) }, }, { @@ -2023,7 +2023,7 @@ func Test_splunkhecReceiver_healthCheck_success(t *testing.T) { }(), assertResponse: func(t *testing.T, status int, body string) { assert.Equal(t, http.StatusOK, status) - assert.Equal(t, responseHecHealthy, body) + assert.JSONEq(t, responseHecHealthy, body) }, }, { @@ -2034,7 +2034,7 @@ func Test_splunkhecReceiver_healthCheck_success(t *testing.T) { }(), assertResponse: func(t *testing.T, status int, body string) { assert.Equal(t, http.StatusBadRequest, status) - assert.Equal(t, responseNoData, body) + assert.JSONEq(t, responseNoData, body) }, }, }