talos/pkg/grpc/middleware/log/log_test.go
Andrey Smirnov 1849b53881
feat: update dependencies
Bump Go modules, linters, other minor dependencies.

Linux 6.12.17, containerd 2.0.3.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2025-03-04 21:03:43 +04:00

44 lines
1020 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package log_test
import (
"testing"
"github.com/stretchr/testify/assert"
metadata "google.golang.org/grpc/metadata"
"github.com/siderolabs/talos/pkg/grpc/middleware/log"
)
func TestExtractMetadata(t *testing.T) {
for _, test := range []struct {
name string
md metadata.MD
expected string
}{
{
name: "empty",
md: metadata.MD{},
expected: "",
},
{
name: "regular",
md: metadata.Pairs("foo", "bar", "one", "two", "a", "b"),
expected: "a=b;foo=bar;one=two",
},
{
name: "sensitive",
md: metadata.Pairs("foo", "bar", "token", "secret"),
expected: "foo=bar;token=<hidden>",
},
} {
ctx := t.Context()
ctx = metadata.NewIncomingContext(ctx, test.md)
assert.Equal(t, test.expected, log.ExtractMetadata(ctx), test.name)
}
}