Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using dockerCmd when possible #12838

Merged
merged 1 commit into from
Jun 2, 2015
Merged

Using dockerCmd when possible #12838

merged 1 commit into from
Jun 2, 2015

Conversation

fntlnz
Copy link
Member

@fntlnz fntlnz commented Apr 28, 2015

No description provided.

@runcom
Copy link
Member

runcom commented Apr 28, 2015

These files are not properly gofmt'd:
 - integration-cli/docker_cli_ps_test.go

Please reformat the above files using "gofmt -s -w" and commit the result.

runCommandWithOutput(cmd)
cmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
baseOut, _, err := runCommandWithOutput(cmd)
exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello").Run()
Copy link
Member

Choose a reason for hiding this comment

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

check err (even if it wasn't checked)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought to do so, but I preferred to not change it's behaviour. I'm using dockerCmd now.

Copy link
Member

Choose a reason for hiding this comment

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

prob ok

@runcom
Copy link
Member

runcom commented Apr 28, 2015

small nits, rest seems alright

@@ -40,13 +40,12 @@ func (s *DockerSuite) TestEventsContainerFailStartDie(c *check.C) {

out, _ := dockerCmd(c, "images", "-q")
image := strings.Split(out, "\n")[0]
eventsCmd := exec.Command(dockerBinary, "run", "--name", "testeventdie", image, "blerg")
_, _, err := runCommandWithOutput(eventsCmd)
err := exec.Command(dockerBinary, "run", "--name", "testeventdie", image, "blerg").Run()
Copy link
Member

Choose a reason for hiding this comment

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

you could compact the the if below with this statement but it's just sugar

@LK4D4
Copy link
Contributor

LK4D4 commented Apr 28, 2015

I personally hate dockerCmd, so I'm strongly -1 on this. It hides real source of error inside dockerCmd.

@duglin
Copy link
Contributor

duglin commented Apr 28, 2015

@LK4D4 when you say "real source", do you mean the location of the source file (...test.go) that had the bad cmd?

@LK4D4
Copy link
Contributor

LK4D4 commented Apr 28, 2015

@duglin I mean code line too.

@cpuguy83
Copy link
Member

I like it when the cmd you are running is more of a test setup than the actual thing your testing.
So if it does fail then there is something else majorly wrong.

@LK4D4
Copy link
Contributor

LK4D4 commented Apr 28, 2015

I don't like passing *check.C anywhere from tests. It is pretty easy to reduce codebase with asserts now without such things.

@duglin
Copy link
Contributor

duglin commented Apr 28, 2015

@LK4D4 I was just wondering if it would help to have dockerCmd use reflection to figure out the test/line it was called from? I don't have a strong feeling either way but it is kind of nice to not have to add if-statements/Asserts over and over if we can move 'em all into the util func.

@LK4D4
Copy link
Contributor

LK4D4 commented Apr 28, 2015

@duglin I don't feel nice about reading and debugging reflect-code when I can just see where really error was occured. I had problems with that before in integration-cli helpers and I prefer readability over writability and I personally don't care about if err != nil or c.Assert.

@runcom
Copy link
Member

runcom commented May 7, 2015

I personally don't like it either, so before rebasing this, shall we close this and maybe create an issue to remove dockerCmd* entirely from tests? ping @duglin @LK4D4

@cpuguy83
Copy link
Member

cpuguy83 commented May 7, 2015

Actually, go-check does report the correct caller for you.

@duglin
Copy link
Contributor

duglin commented May 7, 2015

I'm probably in the minority here but I don't have a problem with utility functions doing more than setup work. They are certainly good for that but I also view utility functions as things to make writing testcases easier. So, moving code that appears in a lot of tests into a func to save people from having to duplicate that code over and over is ok with me - even if that func is the one doing the functional testing or doing the c.Fatal() call (as long as it reports the proper info so people know which test to look at to see what was being tested).

But I won't -1 removing it since its not that big of an issue - just more replicated code in the test.

@runcom
Copy link
Member

runcom commented May 8, 2015

alright, I think that now that there is gocheck most of the err checking and fataling is handled with a one liner c.Assert. In the end dockerCmd* are just pseudo proxies functions that are just for either not checking the error upstream or setting exec.Command dir or running with a timeout. I think we should have just one standard way of doing all of this otherwise it could be confusing which way to use (other than personal like). I vote for removing dockerCmd* 😄 and have just the runCommand* functions handling everything

@cpuguy83
Copy link
Member

cpuguy83 commented May 8, 2015

heh, I'd say runCommand and runCommandWithOutput are much more superfluous, since these are literally just cmd.Run() and cmd.CombinedOutput(), respectively.

dockerCmd actually provides a level of abstraction.
One might even want something like id := createContainer(), and remove all theses strings.TrimSpace, and custom container names.

@runcom
Copy link
Member

runcom commented May 8, 2015

ok, I just like to have just one way of doing things, above all in tests suite where it's super easy to just implement functions for some use cases and then just forget. Instead a clean interface will make things clear immediately on how to run a container, a container with output etc etc

@LK4D4
Copy link
Contributor

LK4D4 commented May 8, 2015

@runcom @cpuguy83 Btw I noticed that gocheck actually resolves wrong caller problem. So, I'm okay with this if we'll change it to use c.Assert

@runcom
Copy link
Member

runcom commented May 19, 2015

@fntlnz could you please rebase and have dockerCommand using c.Assert?

@fntlnz
Copy link
Member Author

fntlnz commented May 19, 2015

Yeah I'll do all this evening along with the other pr assigned to me.

:)
On May 19, 2015 7:11 PM, "Antonio Murdaca" notifications@github.com wrote:

@fntlnz https://github.com/fntlnz could you please rebase and have
dockerCommand using c.Assert?


Reply to this email directly or view it on GitHub
#12838 (comment).

Signed-off-by: Lorenzo Fontana <fontanalorenzo@me.com>
@fntlnz
Copy link
Member Author

fntlnz commented May 20, 2015

@runcom @LK4D4 looks good to you?

@LK4D4
Copy link
Contributor

LK4D4 commented Jun 2, 2015

LGTM

@LK4D4
Copy link
Contributor

LK4D4 commented Jun 2, 2015

ping @runcom

@calavera
Copy link
Contributor

calavera commented Jun 2, 2015

LGTM. Merging 🎉

calavera added a commit that referenced this pull request Jun 2, 2015
Using dockerCmd when possible
@calavera calavera merged commit 6c42b39 into moby:master Jun 2, 2015
Sign up for free to 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.

8 participants