-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilter_test.go
More file actions
37 lines (31 loc) · 933 Bytes
/
filter_test.go
File metadata and controls
37 lines (31 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package command_test
import (
"io"
"strings"
"testing"
"lesiw.io/command"
"lesiw.io/command/mem"
)
func TestFilterReadFromClosesStdin(t *testing.T) {
m, ctx := mem.Machine(), t.Context()
// Create a command that reads from stdin and writes to stdout
filter := command.NewFilter(ctx, m, "cat")
// Use io.Copy which should trigger ReadFrom and auto-close stdin
src := strings.NewReader("test data")
n, err := io.Copy(filter, src)
if err != nil {
t.Fatalf("io.Copy() error = %v, want nil", err)
}
if got, want := n, int64(9); got != want {
t.Errorf("io.Copy() = %d bytes, want %d", got, want)
}
// Now read from the command - should get the data and EOF
// (indicating stdin was closed properly)
buf, err := io.ReadAll(filter)
if err != nil {
t.Fatalf("io.ReadAll() error = %v, want nil", err)
}
if got, want := string(buf), "test data"; got != want {
t.Errorf("output = %q, want %q", got, want)
}
}