From cfc0ca1f038951f47e5d866481c165c67a372c8d Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Fri, 29 Nov 2024 22:31:31 +0400 Subject: [PATCH] fix(cli): filter out dynamically generated request ID --- cli/test/helper.go | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/cli/test/helper.go b/cli/test/helper.go index 819f4c4c9..14e6f6b78 100644 --- a/cli/test/helper.go +++ b/cli/test/helper.go @@ -1,6 +1,7 @@ package tests import ( + "encoding/json" "fmt" "log" "os" @@ -43,9 +44,9 @@ func ExecuteCliCommand(command string, args ...string) (string, error) { output, err := cmd.CombinedOutput() if err != nil { fmt.Println(fmt.Sprint(err) + ": " + string(output)) - return strings.TrimSpace(string(output)), err + return FilterRequestID(strings.TrimSpace(string(output))), err } - return strings.TrimSpace(string(output)), nil + return FilterRequestID(strings.TrimSpace(string(output))), nil } func SetupCli() { @@ -67,3 +68,39 @@ func SetupCli() { } } + +func FilterRequestID(input string) string { + + if !strings.Contains(input, "requestId") && strings.Contains(input, "reqId") { + return input + } + + // Find the JSON part of the error message + start := strings.Index(input, "{") + end := strings.LastIndex(input, "}") + 1 + + if start == -1 || end == -1 { + return input + } + + jsonPart := input[:start] // Pre-JSON content + + // Parse the JSON object + var errorObj map[string]interface{} + if err := json.Unmarshal([]byte(input[start:end]), &errorObj); err != nil { + return input + } + + // Remove requestId field + delete(errorObj, "requestId") + delete(errorObj, "reqId") + + // Convert back to JSON + filtered, err := json.Marshal(errorObj) + if err != nil { + return input + } + + // Reconstruct the full string + return jsonPart + string(filtered) + input[end:] +}