Skip to content

Commit 7fb3c0f

Browse files
committed
set up vm_test to direct all output to a pipe
Sadly, the original sin of os.Std{in,out,err} requires an os.File, else we could use an in-memory pipe. Signed-off-by: Ronald G Minnich <rminnich@gmail.com>
1 parent f6ff3f3 commit 7fb3c0f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

initramfs/vm_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ package initramfs_test
99
import (
1010
"context"
1111
"errors"
12+
"io"
1213
"os"
1314
"path/filepath"
1415
"testing"
1516

17+
"github.com/u-root/cpu/client"
1618
"github.com/u-root/cpu/initramfs"
1719
)
1820

@@ -57,11 +59,19 @@ func TestCPU(t *testing.T) {
5759
if err != nil {
5860
t.Fatalf("CPUCommand: got %v, want nil", err)
5961
}
62+
client.SetVerbose(t.Logf)
63+
r, w, err := os.Pipe()
64+
cpu.Stdout, cpu.Stderr = w, w
6065

6166
err = cpu.Run()
6267
if err == nil != tt.ok {
6368
t.Errorf("%s %s: got %v, want %v", tt.cmd, tt.args, err == nil != tt.ok, err == nil == tt.ok)
6469
}
70+
b, err := io.ReadAll(r)
71+
if err != nil {
72+
t.Errorf("reading pipe output: got %v, want nil", err)
73+
}
74+
t.Logf("%q", string(b))
6575
}
6676
b, err := os.ReadFile(filepath.Join(d, "b"))
6777
if err != nil {

0 commit comments

Comments
 (0)