Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/common-go/log/context_test.go
2498 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package log
6
7
import (
8
"context"
9
"testing"
10
11
"github.com/sirupsen/logrus"
12
"github.com/stretchr/testify/require"
13
)
14
15
func TestExtract_GracefulWithoutEntryOnContext(t *testing.T) {
16
require.NotNil(t, Extract(context.Background()))
17
}
18
19
func TestExtract(t *testing.T) {
20
ctx := context.Background()
21
22
require.NotNil(t, Extract(context.Background()), "graceful without a context logger")
23
24
withContextLogger := ToContext(ctx, Log)
25
require.Equal(t, Log, Extract(withContextLogger))
26
}
27
28
func TestAddFields(t *testing.T) {
29
ctx := ToContext(context.Background(), Log)
30
fields := logrus.Fields{
31
"some-field": "value",
32
}
33
AddFields(ctx, fields)
34
35
entry := Extract(ctx)
36
require.Equal(t, entry.Data, fields)
37
}
38
39