Skip to content

Commit

Permalink
Adding basic command, testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lovestaco committed Aug 15, 2023
1 parent e1fab89 commit da128e0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
56 changes: 56 additions & 0 deletions tests/basic_commands_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// basic_commands_test.go
package tests

import (
"bytes"
"os/exec"
"strings"
"testing"

"github.com/rs/zerolog/log"
)

func runL2CommandAndGetOutput(t *testing.T, cmdArgs ...string) string {

// Get the full path to the l2 binary
l2BinPath := "../build/l2"

// Check if the l2 binary file exists
if err := checkL2BinaryExists(l2BinPath); err != nil {
t.Error(err)
return ""
}

// Code to run the l2 command
cmd := exec.Command(l2BinPath, cmdArgs...)

var stdout bytes.Buffer
cmd.Stdout = &stdout

var stderr bytes.Buffer
cmd.Stderr = &stderr

// Execute the command
err := cmd.Run()
if err != nil {
log.Error().Str("Error", stderr.String()).Msg("Error running l2 command")
t.Errorf("Error running l2 command: %v\n", err)
return ""
}

// Retrieve the captured stdout
stdoutOutput := stdout.String()
log.Info().Str("Test env_command", stdoutOutput).Msg("output from command")
return stdoutOutput
}

func TestNormalExecution(t *testing.T) {
fpath := "../elfparser/ElfTestSuite/y_0000_basic_get.l2"
cmdArgs := []string{fpath}
output := runL2CommandAndGetOutput(t, cmdArgs...)

expectedOutputPart := "\"url\": \"http://httpbin.org/get\""
if !strings.Contains(output, expectedOutputPart) {
t.Errorf("Expected output to contain %q, but got %q", expectedOutputPart, output)
}
}
5 changes: 3 additions & 2 deletions tests/env_command_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// env_command_test.go
package tests

import (
Expand Down Expand Up @@ -28,7 +29,7 @@ func TestL2EnvCommand(t *testing.T) {
checkBHost(t, envMap)
}

func TestL2EnvForAHOenv(t *testing.T) {
func TestL2RelevantEnvForAString(t *testing.T) {
fpath := "../elfparser/ElfTestSuite/root_variable_override/api/y_0020_root_override.l2"
cmdArgs := []string{"-e=A", fpath}
envMap := runL2CommandAndParseJSON(t, cmdArgs...)
Expand All @@ -40,7 +41,7 @@ func TestL2EnvForAHOenv(t *testing.T) {
checkBHostDoesNotExist(t, envMap)
}

func TestL2EnvForBHOenv(t *testing.T) {
func TestL2RelevantEnvForBString(t *testing.T) {
fpath := "../elfparser/ElfTestSuite/root_variable_override/api/y_0020_root_override.l2"
cmdArgs := []string{"-e=B", fpath}
envMap := runL2CommandAndParseJSON(t, cmdArgs...)
Expand Down

0 comments on commit da128e0

Please sign in to comment.