Skip to content

Commit

Permalink
warn if binary path wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
lovestaco committed Jul 20, 2023
1 parent b411218 commit 04bcc94
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions tests/env_command_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package tests

import (
// "encoding/json"
"bytes"
"encoding/json"
"fmt"
"os/exec"
"testing"
"os"

)

type EnvData struct {
Expand All @@ -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()
Expand All @@ -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)
}
}
}

Expand Down

0 comments on commit 04bcc94

Please sign in to comment.