mv captureStdout as public func

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2022-04-03 22:24:38 +08:00
parent 01b5b79a01
commit e0244bc341
4 changed files with 89 additions and 37 deletions
+40
View File
@@ -0,0 +1,40 @@
package testutil
import (
"fmt"
"testing"
)
// TestCaptureStdout tests the CaptureStdout function.
func TestCaptureStdout(t *testing.T) {
tests := []struct {
output string
expected string
}{
{
output: "123",
expected: "123",
},
{
output: "test",
expected: "test",
},
{
output: "",
expected: "",
},
{
output: "...",
expected: "...",
},
}
for _, test := range tests {
result := CaptureStdout(func() {
fmt.Print(test.output)
})
if result != test.expected {
t.Errorf("CaptureStdout() = %v, want %v", result, test.expected)
}
}
}