Skip to content

Conversation

robbyt
Copy link

@robbyt robbyt commented Sep 14, 2025

Previously, StdioTransport was hardcoded to use os.Stdin and os.Stdout, making it difficult to test transport behavior with controlled input/output. With this change, users can inject custom streams (like io.Pipe()) for testing while maintaining backward compatibility.

This change modifies the Connect method to check the fields, defaulting back to the standard streams as defaults if nil.

Add optional In and Out fields to StdioTransport to allow injection of custom
io.ReadCloser and io.WriteCloser streams. This enables testing with io.Pipe()
instead of requiring os.Stdin/os.Stdout. The Connect method now checks for nil
fields and uses os.Stdin/os.Stdout as defaults.
@findleyr
Copy link
Contributor

This is redundant with #376, which introduces a general IOTransport. I'd like to keep StdioTransport and CmdTransport as distinct types.

Also, for testing in memory, use NewInMemoryTransports, which creates two transports connected to eachother.

@findleyr
Copy link
Contributor

Closing in favor of #376.
Please comment on issue #444 if you disagree with the proposed new API.

@findleyr findleyr closed this Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants