Skip to content

Commit

Permalink
Update tests to use separate string.Builder-s for stdout and stderr
Browse files Browse the repository at this point in the history
string.Builder is a non-comparable type which is not safe for concurrent use
when shared by Cmd.Stdout and Cmd.Stderr. Causes a race condition when accessing
the the builder when Cmd is running.
  • Loading branch information
lornasong committed May 20, 2022
1 parent d6a9ddc commit 7ca7298
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tfexec/internal/e2etest/util_test.go
Expand Up @@ -91,16 +91,21 @@ func runTestVersions(t *testing.T, versions []string, fixtureName string, cb fun
}
}

var stdouterr strings.Builder
tf.SetStdout(&stdouterr)
tf.SetStderr(&stdouterr)
// Separate strings.Builder because it's not concurrent safe
var stdout strings.Builder
tf.SetStdout(&stdout)
var stderr strings.Builder
tf.SetStderr(&stderr)

tf.SetLogger(&testingPrintfer{t})

// TODO: capture panics here?
cb(t, runningVersion, tf)

t.Logf("CLI Output:\n%s", stdouterr.String())
t.Logf("CLI Output:\n%s", stdout.String())
if len(stderr.String()) > 0 {
t.Logf("CLI Error:\n%s", stderr.String())
}
})
}
}
Expand Down

0 comments on commit 7ca7298

Please sign in to comment.