You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
boundary/internal/requests/requests_test.go

51 lines
1.0 KiB

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package requests
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_RequestContextFromCtx(t *testing.T) {
t.Parallel()
type input struct {
name string
input context.Context
output *RequestContext
}
tests := []input{
{
name: "not added",
input: context.Background(),
},
{
name: "added but empty",
input: NewRequestContext(context.Background()),
output: &RequestContext{},
},
{
name: "non-empty",
input: func() context.Context {
ctx := context.WithValue(context.Background(), ContextRequestInformationKey, &RequestContext{
UserId: "u_foo",
})
return ctx
}(),
output: &RequestContext{UserId: "u_foo"},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
reqCtx, ok := RequestContextFromCtx(test.input)
require.Equal(t, test.output == nil, !ok)
assert.Equal(t, test.output, reqCtx)
})
}
}