mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/golangci/golangci-lint](https://redirect.github.com/golangci/golangci-lint) | `v1.61.0` -> `v1.62.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>golangci/golangci-lint (github.com/golangci/golangci-lint)</summary> ### [`v1.62.0`](https://redirect.github.com/golangci/golangci-lint/compare/v1.61.0...v1.62.0) [Compare Source](https://redirect.github.com/golangci/golangci-lint/compare/v1.61.0...v1.62.0) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/open-telemetry/opentelemetry-collector). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS45LjUiLCJ1cGRhdGVkSW5WZXIiOiIzOS45LjUiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImRlcGVuZGVuY2llcyIsInJlbm92YXRlYm90Il19--> --------- Signed-off-by: Bogdan Drutu <[email protected]> Co-authored-by: Hanzo Dev <[email protected]> Co-authored-by: opentelemetrybot <[email protected]> Co-authored-by: Yang Song <[email protected]> Co-authored-by: Bogdan Drutu <[email protected]> Co-authored-by: Yang Song <[email protected]>
95 lines
2.4 KiB
Go
95 lines
2.4 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package configopaque // import "go.opentelemetry.io/collector/config/configopaque"
|
|
|
|
import (
|
|
"encoding"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var _ encoding.TextMarshaler = String("")
|
|
|
|
var _ fmt.Stringer = String("")
|
|
|
|
var _ fmt.GoStringer = String("")
|
|
|
|
var _ encoding.BinaryMarshaler = String("")
|
|
|
|
func TestStringMarshalText(t *testing.T) {
|
|
examples := []String{"opaque", "s", "veryveryveryveryveryveryveryveryveryverylong"}
|
|
for _, example := range examples {
|
|
opaque, err := example.MarshalText()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, maskedString, string(opaque))
|
|
}
|
|
}
|
|
|
|
type TestStruct struct {
|
|
Opaque String `json:"opaque" yaml:"opaque"`
|
|
Plain string `json:"plain" yaml:"plain"`
|
|
}
|
|
|
|
var example = TestStruct{
|
|
Opaque: "opaque",
|
|
Plain: "plain",
|
|
}
|
|
|
|
func TestStringJSON(t *testing.T) {
|
|
bytes, err := json.Marshal(example)
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, `{"opaque":"[REDACTED]","plain":"plain"}`, string(bytes))
|
|
}
|
|
|
|
func TestStringFmt(t *testing.T) {
|
|
examples := []String{"opaque", "s", "veryveryveryveryveryveryveryveryveryverylong"}
|
|
verbs := []string{"%s", "%q", "%v", "%#v", "%+v", "%x"}
|
|
for _, example := range examples {
|
|
for _, verb := range verbs {
|
|
t.Run(fmt.Sprintf("%s/%s", string(example), verb), func(t *testing.T) {
|
|
assert.Equal(t,
|
|
fmt.Sprintf(verb, maskedString),
|
|
fmt.Sprintf(verb, example),
|
|
)
|
|
})
|
|
}
|
|
|
|
for _, verb := range verbs {
|
|
t.Run(fmt.Sprintf("string(%s)/%s", string(example), verb), func(t *testing.T) {
|
|
// converting to a string allows to output as an unredacted string still:
|
|
var expected string
|
|
switch verb {
|
|
case "%s", "%v", "%+v":
|
|
expected = string(example)
|
|
case "%q", "%#v":
|
|
expected = "\"" + string(example) + "\""
|
|
case "%x":
|
|
expected = hex.EncodeToString([]byte(example))
|
|
default:
|
|
t.Errorf("unexpected verb %q", verb)
|
|
}
|
|
|
|
assert.Equal(t,
|
|
expected,
|
|
fmt.Sprintf(verb, string(example)),
|
|
)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestStringMarshalBinary(t *testing.T) {
|
|
examples := []String{"opaque", "s", "veryveryveryveryveryveryveryveryveryverylong"}
|
|
for _, example := range examples {
|
|
opaque, err := example.MarshalBinary()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []byte("[REDACTED]"), opaque)
|
|
}
|
|
}
|