-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
use of checkers on integration-cli/docker_cli_links_test.go
and integration-cli/docker_cli_links_unix_test.go
#16854
Conversation
} else if exitCode != 1 { | ||
c.Fatalf("run ping failed with errors: %v", err) | ||
} | ||
c.Assert(exitCode == 0, check.Equals, false, check.Commentf("run ping did not fail")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can replace that with :
c.Assert(exitCode, check.Equals, 1, check.Commentf("run ping failed with the following error : %v", err))
c.Fatalf("error output expected 'Could not get container', but got %q instead; err: %v", out, err) | ||
} | ||
|
||
c.Assert(err, check.NotNil, check.Commentf("an invalid container target should produce an error")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be just a regular comment
// an invalid container target should produce an error
on the same line or the previous line, and it will be printed out.
6f3ea86
to
a9deed5
Compare
Thank you for your suggestion :) @MHBauer @vdemeester |
@@ -2,8 +2,8 @@ package main | |||
|
|||
import ( | |||
"fmt" | |||
"github.com/docker/docker/pkg/integration/checker" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you reorganize the imports ? like
import (
"fmt"
"regexp"
"strings"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
)
updated :) |
@WeiZhang555 Great ! Small nit, could you use Other than that, looks good 😉. |
@vdemeester |
@WeiZhang555 hum, no, just use |
@WeiZhang555 seems like |
e098386
to
5a29d54
Compare
OK, updated, thank you! @vdemeester |
LGTM 🐱 |
} | ||
|
||
// an invalid container target should produce an error | ||
c.Assert(err, checker.NotNil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include out
in check.Commentf
here, so that if a failure occurs we can see what happened, otherwise we'd generally just get exit status 1
or something from the err.
5a29d54
to
4947272
Compare
@cpuguy83 updated, thank you! |
@WeiZhang555 needs a rebase, sorry 😞 |
4947272
to
593dc3a
Compare
@abronan rebased, thank you! :) |
|
||
c.Assert(err, checker.IsNil, check.Commentf("contentTwo: %s", string(contentTwo))) | ||
// Host is not present in updated hosts file | ||
c.Assert(string(contentTwo), checker.Contains, "onetwo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move the comment in the end of the line or in a check.Commentf(…)
so we don't loose the "context" when this assertion fails ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Host is not present in updated hosts file
c.Assert(string(contentTwo), checker.Contains, "onetwo")
This won't lose the "context", actually "Host is not present in updated hosts file" will also be printed out when the assertion fails since c.Assert
can handle annotation above it as my little test shows.
So that's why I put the context above the c.Assert
statement instead of putting it in check.Commentf
or in the end of the line, that won't make sentence too long to read.
Will this be acceptable? 😄
ping @vdemeester
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep yep, I forgot that it handled the comment above too 😅. My bad 😉 👍
The only thing I'm not sure, if when there is a comment above and a check.Commentf
😝.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, comment above and check.Commentf
can coexists, for example:
code:
// err shouldn't be nil
// second line
// third line
c.Assert(err, check.NotNil, check.Commentf("This is comment"))
output:
----------------------------------------------------------------------
FAIL: docker_api_test.go:20: DockerSuite.TestApiGetEnabledCors
docker_api_test.go:25:
// err shouldn't be nil
// second line
// third line
c.Assert(err, check.NotNil, check.Commentf("This is comment"))
... value = nil
... This is comment
----------------------------------------------------------------------
I quite like this format, what do you think? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay, fine by me then 😉. I actually never tried it out 😅, always used check.Commentf
😝.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
integration-cli/docker_cli_links_test.go
and integration-cli/docker_cli_links_unix_test.go
Any progress ? |
c.Errorf("/etc/hosts should be a regular file") | ||
} | ||
// /etc/hosts should be a regular file | ||
c.Assert(strings.HasPrefix(out, "-"), checker.Equals, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check.Matches
instead?
c.Assert(out, check.Matches, '^-')
Note I have not tested.
If Matches doesn't work, then need to make sure to put out
in a Commentf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that ^-
doesn't work, but ^-.+
works fine.
593dc3a
to
bd4ed50
Compare
@cpuguy83 updated per your suggestion, please help review, thank you! :) |
Part of moby#16756 Use c.Assert instead of condition judgement. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
bd4ed50
to
97b9223
Compare
LGTM |
use of checkers on `integration-cli/docker_cli_links_test.go` and `integration-cli/docker_cli_links_unix_test.go`
Part of #16756
Use c.Assert instead of condition judgement
Signed-off-by: Zhang Wei zhangwei555@huawei.com