Path: blob/main/components/common-go/log/context_test.go
2498 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package log56import (7"context"8"testing"910"github.com/sirupsen/logrus"11"github.com/stretchr/testify/require"12)1314func TestExtract_GracefulWithoutEntryOnContext(t *testing.T) {15require.NotNil(t, Extract(context.Background()))16}1718func TestExtract(t *testing.T) {19ctx := context.Background()2021require.NotNil(t, Extract(context.Background()), "graceful without a context logger")2223withContextLogger := ToContext(ctx, Log)24require.Equal(t, Log, Extract(withContextLogger))25}2627func TestAddFields(t *testing.T) {28ctx := ToContext(context.Background(), Log)29fields := logrus.Fields{30"some-field": "value",31}32AddFields(ctx, fields)3334entry := Extract(ctx)35require.Equal(t, entry.Data, fields)36}373839