fix: resolved comments

This commit is contained in:
mayur.popli
2025-03-28 16:09:31 +05:30
parent c64224032b
commit ead2211960
4 changed files with 20 additions and 19 deletions

View File

@@ -12,8 +12,8 @@ type provider struct{}
func (p provider) New(ctx context.Context, c map[string]string) (func(http.Handler) http.Handler, error) { func (p provider) New(ctx context.Context, c map[string]string) (func(http.Handler) http.Handler, error) {
config := &requestpreprocessor.Config{} config := &requestpreprocessor.Config{}
if checkKeysStr, ok := c["CheckKeys"]; ok { if contextKeysStr, ok := c["ContextKeys"]; ok {
config.CheckKeys = strings.Split(checkKeysStr, ",") config.ContextKeys = strings.Split(contextKeysStr, ",")
} }
return requestpreprocessor.NewUUIDSetter(config) return requestpreprocessor.NewUUIDSetter(config)
} }

View File

@@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
// TODO: Will Split this into success and fail (two test cases)
func TestProviderNew(t *testing.T) { func TestProviderNew(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string

View File

@@ -13,8 +13,8 @@ import (
) )
type Config struct { type Config struct {
CheckKeys []string ContextKeys []string
Role string Role string
} }
type becknRequest struct { type becknRequest struct {
@@ -50,7 +50,7 @@ func NewUUIDSetter(cfg *Config) (func(http.Handler) http.Handler, error) {
subID = req.Context["bpp_id"] subID = req.Context["bpp_id"]
} }
ctx := context.WithValue(r.Context(), subscriberIDKey, subID) ctx := context.WithValue(r.Context(), subscriberIDKey, subID)
for _, key := range cfg.CheckKeys { for _, key := range cfg.ContextKeys {
value := uuid.NewString() value := uuid.NewString()
updatedValue := update(req.Context, key, value) updatedValue := update(req.Context, key, value)
ctx = context.WithValue(ctx, contextKeyType(key), updatedValue) ctx = context.WithValue(ctx, contextKeyType(key), updatedValue)
@@ -90,15 +90,15 @@ func validateConfig(cfg *Config) error {
return errors.New("config cannot be nil") return errors.New("config cannot be nil")
} }
// Check if CheckKeys is empty. // Check if ContextKeys is empty.
if len(cfg.CheckKeys) == 0 { if len(cfg.ContextKeys) == 0 {
return errors.New("checkKeys cannot be empty") return errors.New("ContextKeys cannot be empty")
} }
// Validate that CheckKeys does not contain empty strings. // Validate that ContextKeys does not contain empty strings.
for _, key := range cfg.CheckKeys { for _, key := range cfg.ContextKeys {
if key == "" { if key == "" {
return errors.New("checkKeys cannot contain empty strings") return errors.New("ContextKeys cannot contain empty strings")
} }
} }
return nil return nil

View File

@@ -19,8 +19,8 @@ func TestNewUUIDSetterSuccessCases(t *testing.T) {
{ {
name: "Valid keys, update missing keys with bap role", name: "Valid keys, update missing keys with bap role",
config: &Config{ config: &Config{
CheckKeys: []string{"transaction_id", "message_id"}, ContextKeys: []string{"transaction_id", "message_id"},
Role: "bap", Role: "bap",
}, },
requestBody: map[string]any{ requestBody: map[string]any{
"context": map[string]any{ "context": map[string]any{
@@ -35,8 +35,8 @@ func TestNewUUIDSetterSuccessCases(t *testing.T) {
{ {
name: "Valid keys, do not update existing keys with bpp role", name: "Valid keys, do not update existing keys with bpp role",
config: &Config{ config: &Config{
CheckKeys: []string{"transaction_id", "message_id"}, ContextKeys: []string{"transaction_id", "message_id"},
Role: "bpp", Role: "bpp",
}, },
requestBody: map[string]any{ requestBody: map[string]any{
"context": map[string]any{ "context": map[string]any{
@@ -121,7 +121,7 @@ func TestNewUUIDSetterErrorCases(t *testing.T) {
{ {
name: "Missing context key", name: "Missing context key",
config: &Config{ config: &Config{
CheckKeys: []string{"transaction_id"}, ContextKeys: []string{"transaction_id"},
}, },
requestBody: map[string]any{ requestBody: map[string]any{
"otherKey": "value", "otherKey": "value",
@@ -131,7 +131,7 @@ func TestNewUUIDSetterErrorCases(t *testing.T) {
{ {
name: "Invalid context type", name: "Invalid context type",
config: &Config{ config: &Config{
CheckKeys: []string{"transaction_id"}, ContextKeys: []string{"transaction_id"},
}, },
requestBody: map[string]any{ requestBody: map[string]any{
"context": "not-a-map", "context": "not-a-map",