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

test: refactor test package and add cases #331

Merged
merged 1 commit into from
Dec 19, 2017
Merged

test: refactor test package and add cases #331

merged 1 commit into from
Dec 19, 2017

Conversation

fuweid
Copy link
Contributor

@fuweid fuweid commented Dec 15, 2017

Signed-off-by: Wei Fu fhfuwei@163.com

1.Describe what this PR did

Refactor test package and add more tests

2.Does this pull request fix one issue?
none

3.Describe how you did it

  • runCmd wraps icmd and does the same thing as icmd. In order to make maintainer eaiser, I remove the runCmd and create command package in test package.

  • test package not just test the cli command, but also test the pouch api. For this reason, I create request package to handle the request. And then the host address is stable. We can do initailization work in request package so that case doesn't need to do the duplicate work about initialization.

  • Before this commit, the almost cases doesn't care the result. We need to inspect the result. In this commit, the trick one is pouch start -a -i. In order to test attach and tty, we can create pty to write and read the content.

4.Describe how to verify it
none

5.Special notes for reviews

During testing, I meets some issues:

Ping @Letty5411 @allencloud

)

// PruneAllImages deletes all images from pouchd.
func PruneAllImages(apiClient client.ImageAPIClient) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why func PruneAllImages(apiClient client.ImageAPIClient) error?
Not func (apiClient client.ImageAPIClient) PruneAllImages() error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original idea is that the PruneAllImages is only used in test package. It comes from docker system prune. If you need this in pouch, we can implement it in cli package.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is not in pouch's first stage.
Maybe in the future, we will support this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Make senses

@allencloud
Copy link
Collaborator

allencloud commented Dec 18, 2017

All test case fails with the stderr output:

    t.Fatalf("at %s:%d - %s\n", filepath.Base(file), line, err.Error())
... Error: at pouch_cli_create_test.go:25 - 
Command:  /usr/local/bin/pouch pull registry.hub.docker.com/library/busybox:latest
ExitCode: 2
Error:    exit status 2
Stdout:   
Stderr:   panic: provided file is not a console

@allencloud
Copy link
Collaborator

allencloud commented Dec 18, 2017

test package not just test the cli command, but also test the pouch api. For this reason, I create request package to handle the request. And then the host address is stable. We can do initailization work in request package so that case doesn't need to do the duplicate work about initialization.

I totally support this idea.

@sunyuan3
Copy link
Contributor

@fuweid
Copy link
Contributor Author

fuweid commented Dec 18, 2017

Hi @sunyuan3 and @allencloud , the CI is expected to be failed. I try to fix this issue in #345

@allencloud
Copy link
Collaborator

#345 has been merged. Please rebase this. @0x04C2

@fuweid
Copy link
Contributor Author

fuweid commented Dec 19, 2017

Got it. Hold on a sec.

Signed-off-by: Wei Fu <fhfuwei@163.com>
@fuweid
Copy link
Contributor Author

fuweid commented Dec 19, 2017

@allencloud , has been rebased. Please check it.

// {name: "missing image name", args: ""},
} {
res := command.PouchRun("create", tc.args)
c.Assert(res.Error, check.NotNil, check.Commentf(tc.name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I think we should use more c.Assert in test cases. It is much better now. 👍

args := map[string]bool{
"": false,
// getImageInfo is used to retrieve the information about image.
func getImageInfo(apiClient client.ImageAPIClient, name string) (types.ImageInfo, error) {
Copy link
Collaborator

@allencloud allencloud Dec 19, 2017

Choose a reason for hiding this comment

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

We need to add an API GET /images/{idOrName}/json 😄 I recorded this in issue #138

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On my plan. Haha


// running
{
command.PouchRun("start", name).Assert(c, icmd.Success)
Copy link
Collaborator

@allencloud allencloud Dec 19, 2017

Choose a reason for hiding this comment

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

We need to use pouch run to replace create and start, if issue #351 is solved. Just leave a comment to record this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is no need to use run command, because I want to check the created, running and stopped. If I use run, I will miss the created status. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

make sense

"github.com/alibaba/pouch/test/environment"
)

// Get sends request to the default pouchd server with custom request options.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like this package 😄

@@ -507,6 +507,12 @@
"revision": "b5461758462b97cff258bf388ca42110f529d747",
"revisionTime": "2017-11-07T15:27:38Z"
},
{
"checksumSHA1": "jHOLsfeMPcX84YQB2MXBqXFntBg=",
"path": "github.com/kr/pty",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This package is licensed under MIT.
Just comment to mark this.

In the future, we will list all the licenses of vendored package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. I don't realize this. Sorry about that.

It seems that we can do this without pr/tty. I will try.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is all right. Maybe in the future. We need these test very much. I think we could merge this ASAP.

@allencloud
Copy link
Collaborator

allencloud commented Dec 19, 2017

LGTM. Generally.

While I have some tiny suggestion for this PR. These advices all help users could learn test easily.

  • the PouchBinary = "/usr/local/bin/pouch" is a little bit weird. Although it is totally correct, it is not so straight forward for users. However we can prepare that for users, such as, locate binary pouch in $PATH, and then could let user execute cmd := exec.Command("pouch", "start", "-a", "-i", name) rather than exec.Command(environment.PouchBinary, "start", "-a", "-i", name);
  • PouchRun could be ambiguous for users, because it will make users think of command pouch run which will be implemented in the future;
  • Can we find out a way to simplify the Suite configuring thing? Since I think coming to test files to add test cases is the best way for users to quick start.

All the points above is a record, not blocking this pr. We can handle this in follow-ups absolutely.

/cc @sunyuan3 @Letty5411 WDYT?

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Dec 19, 2017
@allencloud
Copy link
Collaborator

Thanks again for your contribution. I am going to merge this. 🍻

@allencloud allencloud merged commit 2664092 into AliyunContainerService:master Dec 19, 2017
@fuweid fuweid deleted the test_update_integration_test branch August 3, 2018 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
areas/test kind/refactor LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants