mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* [logging] Enable storing/extracing of logger from context * Fix * Fix * Fix * Fix * Fix * Fix
38 lines
892 B
Go
38 lines
892 B
Go
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package log
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestExtract_GracefulWithoutEntryOnContext(t *testing.T) {
|
|
require.NotNil(t, Extract(context.Background()))
|
|
}
|
|
|
|
func TestExtract(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
require.NotNil(t, Extract(context.Background()), "graceful without a context logger")
|
|
|
|
withContextLogger := ToContext(ctx, Log)
|
|
require.Equal(t, Log, Extract(withContextLogger))
|
|
}
|
|
|
|
func TestAddFields(t *testing.T) {
|
|
ctx := ToContext(context.Background(), Log)
|
|
fields := logrus.Fields{
|
|
"some-field": "value",
|
|
}
|
|
AddFields(ctx, fields)
|
|
|
|
entry := Extract(ctx)
|
|
require.Equal(t, entry.Data, fields)
|
|
}
|