From 03f18f899335a6eecfdb07cec20922bc33aa2a2b Mon Sep 17 00:00:00 2001 From: lovestaco Date: Thu, 20 Jul 2023 12:13:35 +0530 Subject: [PATCH] chdir to l2 bin, execute and come back --- tests/env_command_test.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/env_command_test.go b/tests/env_command_test.go index c721f389..44ce60d0 100644 --- a/tests/env_command_test.go +++ b/tests/env_command_test.go @@ -16,18 +16,31 @@ type EnvData struct { } func runL2CommandAndParseJSON(t *testing.T, cmdArgs ...string) { - // Construct the relative path to the l2.go executable + // Store the current working directory + originalPath, err := os.Getwd() + if err != nil { + fmt.Println("Error getting the current working directory:", err) + return + } + + // Change the current working directory to lama2Path + l2BinPath := "/home/runner/work/Lama2/Lama2" + err = os.Chdir(l2BinPath) + if err != nil { + fmt.Println("Error changing the current working directory:", err) + return + } cmd := exec.Command("./l2", cmdArgs...) // Use "./l2" as the executable name var stdout bytes.Buffer cmd.Stdout = &stdout // Execute the command - err := cmd.Run() - if err != nil { - // Handle the error if needed - fmt.Printf("Error running l2 command: %v\n", err) - } + // err := cmd.Run() + // if err != nil { + // // Handle the error if needed + // fmt.Printf("Error running l2 command: %v\n", err) + // } // Retrieve the captured stdout stdoutOutput := stdout.String() @@ -53,7 +66,12 @@ func runL2CommandAndParseJSON(t *testing.T, cmdArgs ...string) { if ahost.Val != "`echo http://httpbin.org`" { t.Errorf("Expected \"val\" value to be \"`echo http://httpbin.org`\" for \"AHOST\", but got: %v", ahost.Val) } + } + err = os.Chdir(originalPath) + if err != nil { + fmt.Println("Error changing back to the original working directory:", err) + } } func TestL2EnvCommand(t *testing.T) {