talos/pkg/grpc/middleware/log/log_test.go
Andrey Smirnov 96aa9638f7
chore: rename talos-systems/talos to siderolabs/talos
There's a cyclic dependency on siderolink library which imports talos
machinery back. We will fix that after we get talos pushed under a new
name.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2022-11-03 16:50:32 +04:00

45 lines
1.0 KiB
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 (
"context"
"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 := context.Background()
ctx = metadata.NewIncomingContext(ctx, test.md)
assert.Equal(t, test.expected, log.ExtractMetadata(ctx), test.name)
}
}