Debian Codegraph @

exporters/otlp/otlplog/otlploghttp/internal/partialsuccess_test.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package internal
5
6 import (
7 "strings"
8 "testing"
9
10 "github.com/stretchr/testify/require"
11 )
12
13 func requireErrorString(t *testing.T, expect string, err error) {
14 t.Helper()
15 require.Error(t, err)
16 require.ErrorIs(t, err, PartialSuccess{})
17
18 const pfx = "OTLP partial success: "
19
20 msg := err.Error()
21 require.True(t, strings.HasPrefix(msg, pfx))
22 require.Equal(t, expect, msg[len(pfx):])
23 }
24
25 func TestPartialSuccessFormat(t *testing.T) {
26 requireErrorString(t, "empty message (0 logs rejected)", LogPartialSuccessError(0, ""))
27 requireErrorString(t, "help help (0 logs rejected)", LogPartialSuccessError(0, "help help"))
28 requireErrorString(
29 t,
30 "what happened (10 logs rejected)",
31 LogPartialSuccessError(10, "what happened"),
32 )
33 requireErrorString(t, "what happened (15 logs rejected)", LogPartialSuccessError(15, "what happened"))
34 }