Skip to content
Open
Prev Previous commit
Next Next commit
Add some tests that Pipeline.Start() picks the right stdin/stdout
The most complicated code dealing with `Stage2` is the selection of
which types of stdin/stderr to pass to stages, and that's also the
main advantage of the `Stage2` interface. So add a bunch of tests that
the correct types (especially, `io.Pipe()` vs. `os.Pipe()`) are indeed
being selected.
  • Loading branch information
mhagger committed Dec 17, 2023
commit 34621356648d5ef468f077de13c652a159a4f195
4 changes: 4 additions & 0 deletions pipe/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package pipe

// This file exports a functions to be used only for testing.
var UnwrapNopCloser = unwrapNopCloser
16 changes: 16 additions & 0 deletions pipe/nop_closer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,19 @@ type writerNopCloser struct {
func (w writerNopCloser) Close() error {
return nil
}

// unwrapNopCloser unwraps the object if it is some kind of nop
// closer, and returns the underlying object. This function is used
// only for testing.
func unwrapNopCloser(obj any) (any, bool) {
switch obj := obj.(type) {
case readerNopCloser:
return obj.Reader, true
case readerWriterToNopCloser:
return obj.Reader, true
case writerNopCloser:
return obj.Writer, true
default:
return nil, false
}
}
Loading