Skip to content

Less verbose fake cli - #299

Merged
vdemeester merged 3 commits into
docker:masterfrom
dnephin:less-verbose-fake-cli
Jul 12, 2017
Merged

Less verbose fake cli#299
vdemeester merged 3 commits into
docker:masterfrom
dnephin:less-verbose-fake-cli

Conversation

@dnephin

Copy link
Copy Markdown
Contributor

Almost every use of FakeCli uses a bytes.Buffer for stdout/stderr. Instead of having the caller setup these buffers every time we can default to using a buffer.

I updated some tests to remove unnecessary calls to SetErr() and SetConfigFile(), and a few tests to use the new NewFakeCli(). I've deprecated the only one.

@codecov-io

codecov-io commented Jul 5, 2017

Copy link
Copy Markdown

Codecov Report

Merging #299 into master will not change coverage.
The diff coverage is n/a.

@@ Coverage Diff @@## master #299 +/- ##
=======================================
Coverage 48.68% 48.68% =======================================
Files 186 186 Lines 12416 12416 =======================================
Hits 6045 6045 Misses 5996 5996 Partials 375 375

@aaronlehmann

Copy link
Copy Markdown

What do you think about functional args for NewFakeCli? WithOutput, WithConfigFile, etc. I'm not sure if it's worth it if passing in a buffer is immediately deprecated, but thought I'd offer the suggestion.

It feels like this PR goes halfway, in that it renames the function but doesn't update most tests to use the new style. Would it be difficult to update the tests in the same PR, to avoid touching all these tests multiple times?

@dnephin

Copy link
Copy Markdown
ContributorAuthor

Difficult no, but time consuming, there are lots of instances. A regex wont work because they are almost always on multiple lines. I'll see about converting a few more.

What's bad about touching the files twice?

What do you think about functional args for NewFakeCli? WithOutput, WithConfigFile, etc.

Works for me, but I don't think it's related to this change. They would save a few lines when assigning new values to these fields. This change is about removing unnecessary lines, not replacing necessary ones with helpers.

@aaronlehmann

Copy link
Copy Markdown

What's bad about touching the files twice?

Touching them once would ease review, overall.

Use byte buffers by default, since that is what is done most of the time.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
@dnephin
dnephinforce-pushed the less-verbose-fake-cli branch 2 times, most recently from 07b20fa to 23c3da0CompareJuly 11, 2017 19:02
@dnephin

Copy link
Copy Markdown
ContributorAuthor

Rebased to fix conflicts, and I converted a bunch more tests to use the new function.

I was thinking that the rest would just be handled if/when tests are updated. It's not really a high enough priority that we need to convert them all, but making this change now lets us write all the new tests with the less verbose option. It shouldn't really incur any extra review time because they can be changed as part of updating tests.

Comment threadcli/command/image/load_test.go Outdated
}
for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{imageLoadFunc: tc.imageLoadFunc}, new(bytes.Buffer))
cli := test.NewFakeCliWithOutput(&fakeClient{imageLoadFunc: tc.imageLoadFunc}, new(bytes.Buffer))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could just be NewFakeCli, but I know you're not trying to exhaustively convert these.

Comment threadcli/command/image/load_test.go Outdated
func TestNewLoadCommandInvalidInput(t *testing.T) {
expectedError := "open *"
cmd := NewLoadCommand(test.NewFakeCli(&fakeClient{}, new(bytes.Buffer)))
cmd := NewLoadCommand(test.NewFakeCliWithOutput(&fakeClient{}, new(bytes.Buffer)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could just be NewFakeCli, but I know you're not trying to exhaustively convert these.

Comment threadcli/command/image/remove_test.go Outdated

func TestNewRemoveCommandAlias(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, new(bytes.Buffer)))
cmd := newRemoveCommand(test.NewFakeCliWithOutput(&fakeClient{}, new(bytes.Buffer)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could just be NewFakeCli, but I know you're not trying to exhaustively convert these.

Comment threadcli/command/image/remove_test.go Outdated
}
for _, tc := range testCases {
cmd := NewRemoveCommand(test.NewFakeCli(&fakeClient{
cmd := NewRemoveCommand(test.NewFakeCliWithOutput(&fakeClient{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could just be NewFakeCli, but I know you're not trying to exhaustively convert these.

Comment threadcli/command/image/save_test.go Outdated
}
for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{imageSaveFunc: tc.imageSaveFunc}, new(bytes.Buffer))
cli := test.NewFakeCliWithOutput(&fakeClient{imageSaveFunc: tc.imageSaveFunc}, new(bytes.Buffer))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could just be NewFakeCli, but I know you're not trying to exhaustively convert these.

Comment threadcli/command/stack/list_test.go Outdated

for _, tc := range testCases {
cmd := newListCommand(test.NewFakeCli(&fakeClient{
cmd := newListCommand(test.NewFakeCliWithOutput(&fakeClient{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could just be NewFakeCli, but I know you're not trying to exhaustively convert these.

Comment threadcli/command/stack/remove_test.go Outdated
configs: allConfigs,
}
cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{}))
cmd := newRemoveCommand(test.NewFakeCliWithOutput(cli, &bytes.Buffer{}))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could just be NewFakeCli, but I know you're not trying to exhaustively convert these.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
@dnephin
dnephinforce-pushed the less-verbose-fake-cli branch from 23c3da0 to 42a3800CompareJuly 11, 2017 21:52

@vdemeestervdemeester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 🐯

@vdemeester
vdemeester merged commit fa7687a into docker:masterJul 12, 2017
@GordonTheTurtleGordonTheTurtle added this to the 17.07.0 milestone Jul 12, 2017
@dnephin
dnephin deleted the less-verbose-fake-cli branch July 12, 2017 14:17
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@dnephin@codecov-io@aaronlehmann@vdemeester@GordonTheTurtle