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: add test to images quiet flag #203

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/pouch_cli_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"os/exec"
"regexp"

"github.com/go-check/check"
)
Expand Down Expand Up @@ -38,6 +39,20 @@ func (suite *PouchImagesSuite) TearDownTest(c *check.C) {
// TODO add cleanup work
}

// TestImagesQuietOption is to verify the quiet flag.
func (suite *PouchImagesSuite) TestImagesQuietFlag(c *check.C) {
qOut, _, err := runCmd(exec.Command("pouch", "images", "-q"))
c.Assert(err, check.IsNil)

quietOut, _, err := runCmd(exec.Command("pouch", "images", "--quiet"))
c.Assert(err, check.IsNil)

c.Assert(qOut, check.Equals, quietOut)
if match, _ := regexp.MatchString("^[0-9a-f]+\n$", qOut); !match {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I tried these code by using

Desktop $ cat main.go
package main

import (
	"regexp"
	"fmt"
)

func main(){
	qOut := "123456789"
	if match, _ := regexp.MatchString("^[0-9a-f]+\n$", qOut); !match {
 		fmt.Println("should return numeric ID, but got")
		fmt.Println(qOut)
	}
}

Desktop $ go run main.go
should return numeric ID, but got
123456789

I think 123456789 is a valid image ID, but the regexp will not pass.
Am I wrong?

Copy link
Contributor Author

@fuweid fuweid Nov 30, 2017

Choose a reason for hiding this comment

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

The ID is valid.

But the cli uses fmt.Println to print so that each ID will have the Carriage char at the end.
For the case, the qOut will contains the \n. That is why I put the \n before the $ in the regrex.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case, can we make pouchd pull an image in advance in the integration test of travisCI?
@sunyuan3 @Letty5411

Copy link
Contributor Author

@fuweid fuweid Nov 30, 2017

Choose a reason for hiding this comment

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

BTW, the Windows uses \r\n as Carriage char. I don't have env to test that. 😢 The case maybe fail in Windows...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am afraid no. But we have not planned running on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK! 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@allencloud Yes, I can pull an image in advance in the integration test of travisCI.

Copy link
Contributor

Choose a reason for hiding this comment

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

^[0-9a-f] : this may be changed to ^[0-9] as image ID only contains number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @Letty5411 , the ID is short for SHA256-Digest which is hexadecimal. ID can contains the a-f.

c.Fatalf("should return numeric ID, but got %s", qOut)
}
}

// TestImagesWorks tests "pouch image" work.
func (suite *PouchImagesSuite) TestImagesWorks(c *check.C) {

Expand Down