From 8469239d84bc71bececc5a9027d3a3e0fe683fd6 Mon Sep 17 00:00:00 2001 From: mjarkk Date: Sat, 3 Nov 2018 09:12:45 +0100 Subject: [PATCH] Fixed test --- pkg/commands/exec_live_default.go | 17 ++++++++++++----- pkg/commands/git_test.go | 16 +++------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/pkg/commands/exec_live_default.go b/pkg/commands/exec_live_default.go index 99ad698b5..88bbf2eb4 100644 --- a/pkg/commands/exec_live_default.go +++ b/pkg/commands/exec_live_default.go @@ -20,6 +20,7 @@ import ( // NOTE: You don't have to include a enter in the return data this function will do that for you func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) { cmdOutput := []string{} + canAsk := true splitCmd := ToArgv(command) cmd := exec.Command(splitCmd[0], splitCmd[1:]...) @@ -48,17 +49,23 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s scanner := bufio.NewScanner(tty) scanner.Split(bufio.ScanWords) for scanner.Scan() { - toOutput := re.ReplaceAllString(scanner.Text(), "") - cmdOutput = append(cmdOutput, toOutput) - toWrite := output(toOutput) - if len(toWrite) > 0 { - _, _ = tty.Write([]byte(toWrite + "\n")) + // canAsk prefrents calls to output when the program is already closed + if canAsk { + toOutput := re.ReplaceAllString(scanner.Text(), "") + cmdOutput = append(cmdOutput, toOutput) + toWrite := output(toOutput) + if len(toWrite) > 0 { + _, _ = tty.Write([]byte(toWrite + "\n")) + } } } waitForBufio.Done() }() if err := cmd.Wait(); err != nil { + canAsk = false + + // waitForBufio.Wait() return strings.Join(cmdOutput, " "), err } diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 41bee5078..7f111997c 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -5,7 +5,6 @@ import ( "io/ioutil" "os" "os/exec" - "strings" "testing" "time" @@ -983,7 +982,7 @@ func TestGitCommandPush(t *testing.T) { }, false, func(err error) { - assert.Nil(t, err) + assert.Equal(t, "exit status 128", err.Error()) }, }, { @@ -996,7 +995,7 @@ func TestGitCommandPush(t *testing.T) { }, true, func(err error) { - assert.Nil(t, err) + assert.Equal(t, "exit status 128", err.Error()) }, }, { @@ -1009,7 +1008,7 @@ func TestGitCommandPush(t *testing.T) { }, false, func(err error) { - assert.Nil(t, err) + assert.Equal(t, "exit status 128", err.Error()) }, }, } @@ -1021,15 +1020,6 @@ func TestGitCommandPush(t *testing.T) { err := gitCmd.Push("test", s.forcePush, func(passOrUname string) string { return "-" }) - errMessage := err.Error() - cutrange := 43 - if len(errMessage) < 43 { - cutrange = len(errMessage) - } - testMessage := errMessage[:cutrange] - if strings.Contains("error: src refspec test does not match any.", testMessage) { - err = nil - } s.test(err) }) }