Skip to content

Commit

Permalink
[chore]: use ErrorContains with testify (#11680)
Browse files Browse the repository at this point in the history
#### Description

use ErrorContains with testify when possible

Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 authored Nov 14, 2024
1 parent c5a69c2 commit 51d57f0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 39 deletions.
3 changes: 1 addition & 2 deletions component/componenttest/configtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ func TestCheckConfigStruct(t *testing.T) {
if tt.wantErrMsgSubStr == "" {
assert.NoError(t, err)
} else {
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErrMsgSubStr)
require.ErrorContains(t, err, tt.wantErrMsgSubStr)
}
})
}
Expand Down
4 changes: 1 addition & 3 deletions pdata/internal/json/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ func TestReadValueInvliadBytesValue(t *testing.T) {
defer jsoniter.ConfigFastest.ReturnIterator(iter)

ReadValue(iter, &otlpcommon.AnyValue{})
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "base64")
}
assert.ErrorContains(t, iter.Error, "base64")
}

func TestReadArrayUnknownField(t *testing.T) {
Expand Down
6 changes: 2 additions & 4 deletions pdata/plog/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,15 @@ func TestUnmarshalJsoniterLogWrongTraceID(t *testing.T) {
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewLogRecord().unmarshalJsoniter(iter)
require.Error(t, iter.Error)
assert.Contains(t, iter.Error.Error(), "parse trace_id")
require.ErrorContains(t, iter.Error, "parse trace_id")
}

func TestUnmarshalJsoniterLogWrongSpanID(t *testing.T) {
jsonStr := `{"body":{}, "spanId":"--"}`
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewLogRecord().unmarshalJsoniter(iter)
require.Error(t, iter.Error)
assert.Contains(t, iter.Error.Error(), "parse span_id")
require.ErrorContains(t, iter.Error, "parse span_id")
}

func BenchmarkJSONUnmarshal(b *testing.B) {
Expand Down
8 changes: 2 additions & 6 deletions pdata/pmetric/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,15 @@ func TestExemplarInvalidTraceID(t *testing.T) {
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewExemplar().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse trace_id")
}
assert.ErrorContains(t, iter.Error, "parse trace_id")
}

func TestExemplarInvalidSpanID(t *testing.T) {
jsonStr := `{"spanId":"--"}`
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewExemplar().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse span_id")
}
assert.ErrorContains(t, iter.Error, "parse span_id")
}

func TestExemplar(t *testing.T) {
Expand Down
12 changes: 3 additions & 9 deletions pdata/pprofile/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ func TestUnmarshalJsoniterProfileInvalidProfileIDField(t *testing.T) {
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewProfileContainer().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse profile_id")
}
assert.ErrorContains(t, iter.Error, "parse profile_id")
}

func TestUnmarshalJsoniterResourceProfiles(t *testing.T) {
Expand Down Expand Up @@ -287,19 +285,15 @@ func TestUnmarshalJsoniterLinkInvalidTraceIDField(t *testing.T) {
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewLink().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse trace_id")
}
assert.ErrorContains(t, iter.Error, "parse trace_id")
}

func TestUnmarshalJsoniterSpanLinkInvalidSpanIDField(t *testing.T) {
jsonStr := `{"span_id":"--"}`
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewLink().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse span_id")
}
assert.ErrorContains(t, iter.Error, "parse span_id")
}

func TestUnmarshalJsoniterLabel(t *testing.T) {
Expand Down
20 changes: 5 additions & 15 deletions pdata/ptrace/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,29 +159,23 @@ func TestUnmarshalJsoniterSpanInvalidTraceIDField(t *testing.T) {
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewSpan().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse trace_id")
}
assert.ErrorContains(t, iter.Error, "parse trace_id")
}

func TestUnmarshalJsoniterSpanInvalidSpanIDField(t *testing.T) {
jsonStr := `{"span_id":"--"}`
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewSpan().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse span_id")
}
assert.ErrorContains(t, iter.Error, "parse span_id")
}

func TestUnmarshalJsoniterSpanInvalidParentSpanIDField(t *testing.T) {
jsonStr := `{"parent_span_id":"--"}`
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewSpan().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse parent_span_id")
}
assert.ErrorContains(t, iter.Error, "parse parent_span_id")
}

func TestUnmarshalJsoniterSpanStatus(t *testing.T) {
Expand Down Expand Up @@ -209,19 +203,15 @@ func TestUnmarshalJsoniterSpanLinkInvalidTraceIDField(t *testing.T) {
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewSpanLink().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse trace_id")
}
assert.ErrorContains(t, iter.Error, "parse trace_id")
}

func TestUnmarshalJsoniterSpanLinkInvalidSpanIDField(t *testing.T) {
jsonStr := `{"span_id":"--"}`
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
NewSpanLink().unmarshalJsoniter(iter)
if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "parse span_id")
}
assert.ErrorContains(t, iter.Error, "parse span_id")
}

func TestUnmarshalJsoniterSpanEvent(t *testing.T) {
Expand Down

0 comments on commit 51d57f0

Please sign in to comment.