Skip to content

Commit 110d512

Browse files
mhaggerznull
authored andcommitted
Add some tests that Pipeline.Start() picks the right stdin/stdout
The most complicated code dealing with the change to `Stage.Start()` is the selection of which types of stdin/stderr to pass to stages, and that's also the main advantage of the new interface. So add a bunch of tests that the correct types (especially, `io.Pipe()` vs. `os.Pipe()`) are indeed being selected.
1 parent b97f38b commit 110d512

3 files changed

Lines changed: 396 additions & 0 deletions

File tree

pipe/export_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package pipe
2+
3+
// This file exports a functions to be used only for testing.
4+
var UnwrapNopCloser = unwrapNopCloser

pipe/nop_closer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,19 @@ type writerNopCloser struct {
5151
func (w writerNopCloser) Close() error {
5252
return nil
5353
}
54+
55+
// unwrapNopCloser unwraps the object if it is some kind of nop
56+
// closer, and returns the underlying object. This function is used
57+
// only for testing.
58+
func unwrapNopCloser(obj any) (any, bool) {
59+
switch obj := obj.(type) {
60+
case readerNopCloser:
61+
return obj.Reader, true
62+
case readerWriterToNopCloser:
63+
return obj.Reader, true
64+
case writerNopCloser:
65+
return obj.Writer, true
66+
default:
67+
return nil, false
68+
}
69+
}

0 commit comments

Comments
 (0)