Skip to content

Commit

Permalink
testing simplified logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 committed Apr 2, 2024
1 parent 03cc17d commit 21c7912
Showing 1 changed file with 6 additions and 38 deletions.
44 changes: 6 additions & 38 deletions gauntlet/gauntlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package gauntlet

import (
"bufio"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -73,7 +72,6 @@ type ExecCommandOptions struct {
//
// It will also check for any errors you specify in the output via the errHandling slice.
func (g *Gauntlet) ExecCommand(args []string, options ExecCommandOptions) (string, error) {
output := ""
var updatedArgs []string
if g.Command == "gauntlet" {
updatedArgs = append([]string{g.Command}, args...)
Expand All @@ -89,39 +87,16 @@ func (g *Gauntlet) ExecCommand(args []string, options ExecCommandOptions) (strin
if execDir != "" {
cmd.Dir = execDir
}
stdout, _ := cmd.StdoutPipe()
stderr, _ := cmd.StderrPipe()
cmdErr := cmd.Start()

reader := bufio.NewReader(stdout)
line, err := reader.ReadString('\n')
for err == nil {
log.Info().Str("stdout", line).Msg(g.Command)
output = fmt.Sprintf("%s%s", output, line)

log.Info().Str("stdout buffer", fmt.Sprintf("%d %d", reader.Buffered(), reader.Size())).Msg(g.Command)
if reader.Buffered() == 0 {
break
}
line, err = reader.ReadString('\n')
}

reader = bufio.NewReader(stderr)
line, err = reader.ReadString('\n')
for err == nil {
log.Info().Str("stderr", line).Msg(g.Command)
output = fmt.Sprintf("%s%s", output, line)
stdoutStdErr, err := cmd.CombinedOutput()
output := string(stdoutStdErr)

log.Info().Str("stderr buffer", fmt.Sprintf("%d %d", reader.Buffered(), reader.Size())).Msg(g.Command)
if reader.Buffered() == 0 {
break
}
line, err = reader.ReadString('\n')
for _, line := range strings.Split(output, "\n") {
log.Info().Str("stdoutStdErr", line)
}

// return cmdErr from before, after stdout + stderr logging
if cmdErr != nil {
return output, cmdErr
if err != nil {
return output, err
}

if options.CheckErrorsInRead {
Expand All @@ -131,13 +106,6 @@ func (g *Gauntlet) ExecCommand(args []string, options ExecCommandOptions) (strin
}
}

if strings.Compare("EOF", err.Error()) > 0 {
return output, err
}

// catch any exit codes
err = cmd.Wait()

log.Debug().Str("Command", g.Command).Msg("command Completed")
return output, err
}
Expand Down

0 comments on commit 21c7912

Please sign in to comment.