-
Notifications
You must be signed in to change notification settings - Fork 12
/
context_test.go
49 lines (41 loc) · 1.38 KB
/
context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
Copyright © 2024 Acronis International GmbH.
Released under MIT license.
*/
package middleware
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/acronis/go-appkit/log"
)
func TestGetLoggerFromContext(t *testing.T) {
t.Run("empty logger", func(t *testing.T) {
require.Nil(t, GetLoggerFromContext(context.Background()))
})
t.Run("non empty logger", func(t *testing.T) {
logger := log.NewDisabledLogger()
ctx := NewContextWithLogger(context.Background(), logger)
require.Equal(t, logger, GetLoggerFromContext(ctx))
})
}
func TestGetRequestIDFromContext(t *testing.T) {
t.Run("empty external request ID", func(t *testing.T) {
require.Equal(t, "", GetRequestIDFromContext(context.Background()))
})
t.Run("non empty external request ID", func(t *testing.T) {
const reqID = "external-request-id"
ctx := NewContextWithRequestID(context.Background(), reqID)
require.Equal(t, reqID, GetRequestIDFromContext(ctx))
})
}
func TestGetInternalRequestIDFromContext(t *testing.T) {
t.Run("empty internal request ID", func(t *testing.T) {
require.Equal(t, "", GetInternalRequestIDFromContext(context.Background()))
})
t.Run("non empty internal request ID", func(t *testing.T) {
const reqID = "internal-request-id"
ctx := NewContextWithInternalRequestID(context.Background(), reqID)
require.Equal(t, reqID, GetInternalRequestIDFromContext(ctx))
})
}