Skip to content

test/helpers: introduce CmdStreamBuffer to manipulate a command's output #12252

Merged
nebril merged 2 commits intomasterfrom
pr/rolinh/test-cmd-stderr
Jun 24, 2020
Merged

test/helpers: introduce CmdStreamBuffer to manipulate a command's output #12252
nebril merged 2 commits intomasterfrom
pr/rolinh/test-cmd-stderr

Conversation

@rolinh
Copy link
Copy Markdown
Member

@rolinh rolinh commented Jun 24, 2020

The current implementation of CmdRes allows to perform a certain
number of operations on the standard output stream of a command.
However, these operations are not available for the standard error
stream of a command.

This commit adds a new type, CmdStreamBuffer which is a superset of
Buffer. It has basic operations to process the buffered stream namely
ByLines(), KVOutput(), Filter(), FilterLineJSONPath() and
FilterLines(). These methods, which were part of CmdRes, are still
available to CmdRes but they have been updated to call the respective
methods from the standard output stream's corresponding methods.

Two new methods have been added to CmdRes: GetStdOut() which returns
a CmdStreamBuffer for the standard output stream and GetStdErr()
which returns a CmdStreamBuffer for the standard error stream.
The new methods Stdout() and Stderr() return the respective buffers
content as string. The method Output(), which return the CmdRes
stdout has been removed to avoid any confusion.

All Go code in tests has been adapted to these changes.

@rolinh rolinh added kind/enhancement This would improve or streamline existing functionality. area/CI Continuous Integration testing issue or flake release-note/ci This PR makes changes to the CI. labels Jun 24, 2020
@rolinh rolinh requested a review from gandro June 24, 2020 08:43
@rolinh rolinh force-pushed the pr/rolinh/test-cmd-stderr branch from 7d1cc2d to c282642 Compare June 24, 2020 09:02
@coveralls
Copy link
Copy Markdown

coveralls commented Jun 24, 2020

Coverage Status

Coverage increased (+0.03%) to 37.178% when pulling 31e9af5 on pr/rolinh/test-cmd-stderr into 790bdb9 on master.

@rolinh
Copy link
Copy Markdown
Member Author

rolinh commented Jun 24, 2020

test-me-please

@rolinh rolinh marked this pull request as ready for review June 24, 2020 09:37
@rolinh rolinh requested a review from a team as a code owner June 24, 2020 09:37
Copy link
Copy Markdown
Member

@nebril nebril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Copy Markdown
Member

@nebril nebril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rolinh added 2 commits June 24, 2020 13:44
The current implementation of `CmdRes` allows to perform a certain
number of operations on the standard output stream of a command.
However, these operations are not available for the standard error
stream of a command.

This commit adds a new type, `CmdStreamBuffer` which is a superset of
`Buffer`. It has basic operations to process the buffered stream namely
`ByLines()`, `KVOutput()`, `Filter()`, `FilterLineJSONPath()` and
`FilterLines()`. These methods, which were part of `CmdRes`, are still
available to `CmdRes` but they have been updated to call the respective
methods from the standard output stream's corresponding methods.

Two new methods have been added to `CmdRes`: `GetStdOut()` which returns
a `CmdStreamBuffer` for the standard output stream and `GetStdErr()`
which returns a `CmdStreamBuffer` for the standard error stream.
The new methods `Stdout()` and `Stderr()` return the respective buffers
content as string. The method `Output()`, which return the `CmdRes`
stdout has been removed to avoid any confusion.

All Go code in tests has been adapted to these changes.

Signed-off-by: Robin Hahling <robin.hahling@gw-computing.net>
Handling both `\n` and `\r\n` was part of `CmdRes` already but this
treatment has never been propagated to `FilterBuffer`.

Signed-off-by: Robin Hahling <robin.hahling@gw-computing.net>
@rolinh rolinh force-pushed the pr/rolinh/test-cmd-stderr branch from c282642 to 31e9af5 Compare June 24, 2020 11:45
@rolinh
Copy link
Copy Markdown
Member Author

rolinh commented Jun 24, 2020

test-me-please

@rolinh
Copy link
Copy Markdown
Member Author

rolinh commented Jun 24, 2020

@nebril Yup, noticed and hopefully fixed.

Copy link
Copy Markdown
Member

@nebril nebril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will monitor whether this breaks nightly, but let's ship it.

@maintainer-s-little-helper maintainer-s-little-helper Bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 24, 2020
@nebril nebril merged commit 4e280dd into master Jun 24, 2020
@nebril nebril deleted the pr/rolinh/test-cmd-stderr branch June 24, 2020 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/CI Continuous Integration testing issue or flake kind/enhancement This would improve or streamline existing functionality. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/ci This PR makes changes to the CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants