From e5bee669e469f3a8f688a5bc820f006a94ec959e Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:03:52 -0400 Subject: [PATCH] backport of commit d5f4243c9efe3970ccf0c6227c27bb2c03f02a31 (#23162) Co-authored-by: Hamid Ghaf <83242695+hghaf099@users.noreply.github.com> --- command/agent_test.go | 45 ++++++++++++++++++++++++++++--------------- command/proxy_test.go | 12 ++++++++---- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/command/agent_test.go b/command/agent_test.go index a87572e29..7d1b754c2 100644 --- a/command/agent_test.go +++ b/command/agent_test.go @@ -376,14 +376,14 @@ listener "tcp" { cmd.client = serverClient cmd.startedCh = make(chan struct{}) + var output string + var code int wg := &sync.WaitGroup{} wg.Add(1) go func() { - code := cmd.Run([]string{"-config", configPath}) + code = cmd.Run([]string{"-config", configPath}) if code != 0 { - t.Errorf("non-zero return code when running agent: %d", code) - t.Logf("STDOUT from agent:\n%s", ui.OutputWriter.String()) - t.Logf("STDERR from agent:\n%s", ui.ErrorWriter.String()) + output = ui.ErrorWriter.String() + ui.OutputWriter.String() } wg.Done() }() @@ -398,6 +398,9 @@ listener "tcp" { defer func() { cmd.ShutdownCh <- struct{}{} wg.Wait() + if code != 0 { + t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output) + } }() //---------------------------------------------------- @@ -2624,14 +2627,14 @@ listener "tcp" { cmd.client = serverClient cmd.startedCh = make(chan struct{}) + var output string + var code int wg := &sync.WaitGroup{} wg.Add(1) go func() { - code := cmd.Run([]string{"-config", configPath}) + code = cmd.Run([]string{"-config", configPath}) if code != 0 { - t.Errorf("non-zero return code when running agent: %d", code) - t.Logf("STDOUT from agent:\n%s", ui.OutputWriter.String()) - t.Logf("STDERR from agent:\n%s", ui.ErrorWriter.String()) + output = ui.ErrorWriter.String() + ui.OutputWriter.String() } wg.Done() }() @@ -2646,6 +2649,9 @@ listener "tcp" { defer func() { cmd.ShutdownCh <- struct{}{} wg.Wait() + if code != 0 { + t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output) + } }() conf := api.DefaultConfig() @@ -2939,12 +2945,13 @@ func TestAgent_Config_ReloadTls(t *testing.T) { logger := logging.NewVaultLogger(hclog.Trace) ui, cmd := testAgentCommand(t, logger) + var output string + var code int wg.Add(1) args := []string{"-config", configFile.Name()} go func() { - if code := cmd.Run(args); code != 0 { - output := ui.ErrorWriter.String() + ui.OutputWriter.String() - t.Errorf("got a non-zero exit status: %s", output) + if code = cmd.Run(args); code != 0 { + output = ui.ErrorWriter.String() + ui.OutputWriter.String() } wg.Done() }() @@ -3011,8 +3018,11 @@ func TestAgent_Config_ReloadTls(t *testing.T) { // Shut down cmd.ShutdownCh <- struct{}{} - wg.Wait() + + if code != 0 { + t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output) + } } // TestAgent_NonTLSListener_SIGHUP tests giving a SIGHUP signal to a listener @@ -3056,12 +3066,13 @@ vault { cmd.startedCh = make(chan struct{}) + var output string + var code int wg := &sync.WaitGroup{} wg.Add(1) go func() { - if code := cmd.Run([]string{"-config", configPath}); code != 0 { - output := ui.ErrorWriter.String() + ui.OutputWriter.String() - t.Errorf("got a non-zero exit status: %s", output) + if code = cmd.Run([]string{"-config", configPath}); code != 0 { + output = ui.ErrorWriter.String() + ui.OutputWriter.String() } wg.Done() }() @@ -3082,6 +3093,10 @@ vault { close(cmd.ShutdownCh) wg.Wait() + + if code != 0 { + t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output) + } } // Get a randomly assigned port and then free it again before returning it. diff --git a/command/proxy_test.go b/command/proxy_test.go index a77aeab4d..9b30af922 100644 --- a/command/proxy_test.go +++ b/command/proxy_test.go @@ -1193,12 +1193,13 @@ func TestProxy_Config_ReloadTls(t *testing.T) { logger := logging.NewVaultLogger(hclog.Trace) ui, cmd := testProxyCommand(t, logger) + var output string + var code int wg.Add(1) args := []string{"-config", configFile.Name()} go func() { - if code := cmd.Run(args); code != 0 { - output := ui.ErrorWriter.String() + ui.OutputWriter.String() - t.Errorf("got a non-zero exit status: %s", output) + if code = cmd.Run(args); code != 0 { + output = ui.ErrorWriter.String() + ui.OutputWriter.String() } wg.Done() }() @@ -1265,6 +1266,9 @@ func TestProxy_Config_ReloadTls(t *testing.T) { // Shut down cmd.ShutdownCh <- struct{}{} - wg.Wait() + + if code != 0 { + t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output) + } }