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

use of checkers on integration-cli/docker_cli_links_test.go and integration-cli/docker_cli_links_unix_test.go #16854

Merged
merged 1 commit into from
Oct 19, 2015

Conversation

WeiZhang555
Copy link
Contributor

Part of #16756

Use c.Assert instead of condition judgement

Signed-off-by: Zhang Wei zhangwei555@huawei.com

} 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"))
Copy link
Member

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"))
Copy link
Contributor

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.

@WeiZhang555 WeiZhang555 force-pushed the inte-test branch 2 times, most recently from 6f3ea86 to a9deed5 Compare October 9, 2015 04:05
@WeiZhang555
Copy link
Contributor Author

Thank you for your suggestion :) @MHBauer @vdemeester
Refreshed and updated integration file integration-cli/docker_cli_links_unix_test.go too

@@ -2,8 +2,8 @@ package main

import (
"fmt"
"github.com/docker/docker/pkg/integration/checker"
Copy link
Member

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"
)

@WeiZhang555
Copy link
Contributor Author

updated :)
@vdemeester

@vdemeester
Copy link
Member

@WeiZhang555 Great ! Small nit, could you use checker (like checker.Equals, etc…) instead of checker on every checker so it's more coherent ? 😝.

Other than that, looks good 😉.

@WeiZhang555
Copy link
Contributor Author

@vdemeester
Updated. But check.Commentf has no replacement like checker.Commentf, maybe we should add one more checker.Commentf in pkg/integration/checker/checker.go, WDYT?

@WeiZhang555 WeiZhang555 closed this Oct 9, 2015
@WeiZhang555 WeiZhang555 reopened this Oct 9, 2015
@vdemeester
Copy link
Member

@WeiZhang555 hum, no, just use checker on the "checker" argument (the 2nd) 😝. For now at least 😅.

@vdemeester
Copy link
Member

@WeiZhang555 seems like docker_cli_links_unix_test.go misses an import of checker (github.com/docker/docker/pkg/integration/checker) 😅

@WeiZhang555
Copy link
Contributor Author

OK, updated, thank you! @vdemeester

@vdemeester
Copy link
Member

LGTM 🐱

}

// an invalid container target should produce an error
c.Assert(err, checker.NotNil)
Copy link
Member

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.

@WeiZhang555
Copy link
Contributor Author

@cpuguy83 updated, thank you!

@abronan
Copy link
Contributor

abronan commented Oct 10, 2015

@WeiZhang555 needs a rebase, sorry 😞

@WeiZhang555
Copy link
Contributor Author

@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")
Copy link
Member

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 ?

Copy link
Contributor Author

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

Copy link
Member

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 😝.

Copy link
Contributor Author

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? 😄

Copy link
Member

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 😝.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄

@WeiZhang555 WeiZhang555 changed the title use of checkers on Integration test use of checkers on integration-cli/docker_cli_links_test.go and integration-cli/docker_cli_links_unix_test.go Oct 12, 2015
@WeiZhang555
Copy link
Contributor Author

Any progress ?

@vdemeester
Copy link
Member

Still LGTM for me
ping @cpuguy83 @calavera @abronan

c.Errorf("/etc/hosts should be a regular file")
}
// /etc/hosts should be a regular file
c.Assert(strings.HasPrefix(out, "-"), checker.Equals, true)
Copy link
Member

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.

Copy link
Contributor Author

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.

@WeiZhang555
Copy link
Contributor Author

@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>
@cpuguy83
Copy link
Member

LGTM

cpuguy83 added a commit that referenced this pull request Oct 19, 2015
use of checkers on `integration-cli/docker_cli_links_test.go` and `integration-cli/docker_cli_links_unix_test.go`
@cpuguy83 cpuguy83 merged commit df15523 into moby:master Oct 19, 2015
@WeiZhang555 WeiZhang555 deleted the inte-test branch October 20, 2015 01:50
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.

6 participants