From 04bcc9416499ff76a686cd322c2f6864a970b20c Mon Sep 17 00:00:00 2001 From: lovestaco Date: Thu, 20 Jul 2023 19:55:38 +0530 Subject: [PATCH] warn if binary path wrong --- tests/env_command_test.go | 48 +++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/tests/env_command_test.go b/tests/env_command_test.go index f8bedd62..32813473 100644 --- a/tests/env_command_test.go +++ b/tests/env_command_test.go @@ -1,12 +1,13 @@ package tests import ( - // "encoding/json" "bytes" "encoding/json" "fmt" "os/exec" "testing" + "os" + ) type EnvData struct { @@ -15,22 +16,28 @@ type EnvData struct { } func runL2CommandAndParseJSON(t *testing.T, cmdArgs ...string) { - // Get the full path to the l2 binary - l2BinPath := "/home/runner/work/Lama2/Lama2/build/l2" + // Get the full path to the l2 binary + l2BinPath := "/home/runner/work/Lama2/Lama2/build/l2" + + // Check if the l2 binary file exists + if _, err := os.Stat(l2BinPath); os.IsNotExist(err) { + fmt.Printf("Error: l2 binary not found in the build folder %s, please change the path.\n", l2BinPath) + return + } - // Your existing code to run the l2 command and parse JSON - cmd := exec.Command(l2BinPath, cmdArgs...) + // Your existing code to run the l2 command and parse JSON + cmd := exec.Command(l2BinPath, cmdArgs...) - var stdout bytes.Buffer - cmd.Stdout = &stdout + 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) - return - } + // Execute the command + err := cmd.Run() + if err != nil { + // Handle the error if needed + fmt.Printf("Error running l2 command: %v\n", err) + return + } // Retrieve the captured stdout stdoutOutput := stdout.String() @@ -57,7 +64,18 @@ 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) } - + } + // Example assertion: Check the "BHOST" key + if bhost, ok := envMap["BHOST"]; !ok { + t.Error("Expected 'BHOST' key in the JSON, but it was not found") + } else { + // Example assertion: Check the "BHOST" src and val values + if bhost.Src != "l2configenv" { + t.Errorf(`Expected "src" value to be "l2configenv" for "BHOST", but got: %v`, bhost.Src) + } + if bhost.Val != "https://httpbin.org" { + t.Errorf(`Expected "val" value to be "https://httpbin.org" for "BHOST", but got: %v`, bhost.Val) + } } }