* [COMPLIANCE] Update Copyright and License Headers * chore: make gen to generate files with copyright headers * chore: update missed copyright headers --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
// Copyright IBM Corp. 2020, 2025
|
|
// 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)
|
|
})
|
|
}
|
|
}
|