{"action":"created","comment":{"url":"https://api.github.com/repos/coreos/rkt/pulls/comments/40426187","id":40426187,"diff_hunk":"@@ -0,0 +1,178 @@\n+// Copyright 2015 The rkt Authors\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package main\n+\n+import (\n+\t\"fmt\"\n+\t\"os\"\n+\t\"strings\"\n+\t\"testing\"\n+\n+\t\"github.com/coreos/rkt/Godeps/_workspace/src/github.com/steveeJ/gexpect\"\n+)\n+\n+type ImageId struct {\n+\tpath string\n+\thash string\n+}\n+\n+func (imgId *ImageId) getShortHash(length int) (string, error) {\n+\thashLen := 1 + length\n+\tif hashLen > len(imgId.hash) {\n+\t\treturn \"\", fmt.Errorf(\"getShortHash: Hash %s is shorter than %d chars\", imgId.hash, hashLen)\n+\t}\n+\n+\treturn imgId.hash[:hashLen], nil\n+}\n+\n+// containsConflictingHash returns an ImageId pair if a conflicting short hash is found. The minimum\n+// hash of 2 char is used for comparisons.\n+func (imgId *ImageId) containsConflictingHash(imgIds []ImageId) (imgIdPair []ImageId, found bool) {\n+\tshortHash, err := imgId.getShortHash(2)\n+\tif err != nil {\n+\t\tpanic(fmt.Sprintf(\"containsConflictingHash: %s\", err))\n+\t}\n+\n+\tfor _, iId := range imgIds {\n+\t\tif strings.HasPrefix(iId.hash, shortHash) {\n+\t\t\timgIdPair = []ImageId{*imgId, iId}\n+\t\t\tfound = true\n+\t\t\tbreak\n+\t\t}\n+\t}\n+\treturn\n+}\n+\n+// TestShortHash tests that the short hash generated by the rkt image list\n+// command is usable by the commands that accept image hashes.\n+func TestShortHash(t *testing.T) {\n+\tvar (\n+\t\timageIds []ImageId\n+\t\titer     int\n+\t)\n+\n+\tfor {\n+\t\timage := patchTestACI(fmt.Sprintf(\"rkt-shorthash-%d.aci\", iter), fmt.Sprintf(\"--name=shorthash--%d\", iter))\n+\t\tdefer os.Remove(image)\n+\n+\t\timageHash := getHashOrPanic(image)\n+\t\timageId := ImageId{image, imageHash}\n+\n+\t\timageIdPair, isMatch := imageId.containsConflictingHash(imageIds)\n+\t\tif isMatch {\n+\t\t\timageIds = imageIdPair\n+\t\t\tbreak\n+\t\t} else {\n+\t\t\timageIds = append(imageIds, imageId)\n+\t\t\titer++\n+\t\t}\n+\t}\n+\tctx := newRktRunCtx()\n+\tdefer ctx.cleanup()\n+\n+\t// Pull images into cas\n+\tfor _, imageId := range imageIds {\n+\t\tcmd := fmt.Sprintf(\"%s --insecure-skip-verify fetch %s\", ctx.cmd(), imageId.path)\n+\t\tt.Logf(\"Fetching %s: %v\", imageId.path, cmd)\n+\t\tchild, err := gexpect.Spawn(cmd)\n+\t\tif err != nil {\n+\t\t\tt.Fatalf(\"Cannot exec: %v\", err)\n+\t\t}\n+\t\tif err := child.Wait(); err != nil {\n+\t\t\tt.Fatalf(\"rkt didn't terminate correctly: %v\", err)\n+\t\t}\n+\t}\n+\n+\t// Get hash from 'rkt image list'\n+\timageListCmd := fmt.Sprintf(\"%s image list --fields=key --no-legend\", ctx.cmd())\n+\tchild, err := gexpect.Spawn(imageListCmd)\n+\tif err != nil {\n+\t\tt.Fatal(\"Cannot exec rkt image list\")\n+\t}\n+\n+\thash := fmt.Sprintf(\"sha512-%s\", imageIds[0].hash[:12])\n+\tif err = expectWithOutput(child, hash); err != nil {","path":"tests/rkt_image_list_test.go","position":106,"original_position":106,"commit_id":"827e1695eec75e186c79aabefa7da002bb979da1","original_commit_id":"827e1695eec75e186c79aabefa7da002bb979da1","user":{"login":"alban","id":27575,"avatar_url":"https://avatars.githubusercontent.com/u/27575?v=3","gravatar_id":"","url":"https://api.github.com/users/alban","html_url":"https://github.com/alban","followers_url":"https://api.github.com/users/alban/followers","following_url":"https://api.github.com/users/alban/following{/other_user}","gists_url":"https://api.github.com/users/alban/gists{/gist_id}","starred_url":"https://api.github.com/users/alban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alban/subscriptions","organizations_url":"https://api.github.com/users/alban/orgs","repos_url":"https://api.github.com/users/alban/repos","events_url":"https://api.github.com/users/alban/events{/privacy}","received_events_url":"https://api.github.com/users/alban/received_events","type":"User","site_admin":false},"body":"The duplicate hash should be printed twice by `rkt image list`, right? It could be expected twice.","created_at":"2015-09-25T12:58:06Z","updated_at":"2015-09-25T12:58:06Z","html_url":"https://github.com/coreos/rkt/pull/1455#discussion_r40426187","pull_request_url":"https://api.github.com/repos/coreos/rkt/pulls/1455","_links":{"self":{"href":"https://api.github.com/repos/coreos/rkt/pulls/comments/40426187"},"html":{"href":"https://github.com/coreos/rkt/pull/1455#discussion_r40426187"},"pull_request":{"href":"https://api.github.com/repos/coreos/rkt/pulls/1455"}}},"pull_request":{"url":"https://api.github.com/repos/coreos/rkt/pulls/1455","id":45679909,"html_url":"https://github.com/coreos/rkt/pull/1455","diff_url":"https://github.com/coreos/rkt/pull/1455.diff","patch_url":"https://github.com/coreos/rkt/pull/1455.patch","issue_url":"https://api.github.com/repos/coreos/rkt/issues/1455","number":1455,"state":"open","locked":false,"title":"stage0: implement image list --full flag","user":{"login":"blixtra","id":115075,"avatar_url":"https://avatars.githubusercontent.com/u/115075?v=3","gravatar_id":"","url":"https://api.github.com/users/blixtra","html_url":"https://github.com/blixtra","followers_url":"https://api.github.com/users/blixtra/followers","following_url":"https://api.github.com/users/blixtra/following{/other_user}","gists_url":"https://api.github.com/users/blixtra/gists{/gist_id}","starred_url":"https://api.github.com/users/blixtra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blixtra/subscriptions","organizations_url":"https://api.github.com/users/blixtra/orgs","repos_url":"https://api.github.com/users/blixtra/repos","events_url":"https://api.github.com/users/blixtra/events{/privacy}","received_events_url":"https://api.github.com/users/blixtra/received_events","type":"User","site_admin":false},"body":"The output of rkt image list was not very pleasant due to the very\r\nlong hash and data format. This change shortens the hash to use the\r\nfirst 12 alphanumeric digits after the '-' char. The date format is\r\nchanged to use a human readable format such as \"5 days ago\". For this, a new dependency was added, github.com/dustin/go-humanize.\r\n\r\nIf one care to have the older output format, she can use the newly\r\nintroduced --full flag. Similar to the --full flag in rkt list, this\r\nprovides a full hash and date output string.\r\n\r\nA follow up change needs to be made so that the commands that take the\r\nimage hash as an argument can use the short form. Currently the short\r\nversion of the hash is of little use other than viewing","created_at":"2015-09-22T15:41:36Z","updated_at":"2015-09-25T12:58:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f34d8e91b24902830364015da778ad87ead19ef8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/coreos/rkt/pulls/1455/commits","review_comments_url":"https://api.github.com/repos/coreos/rkt/pulls/1455/comments","review_comment_url":"https://api.github.com/repos/coreos/rkt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coreos/rkt/issues/1455/comments","statuses_url":"https://api.github.com/repos/coreos/rkt/statuses/827e1695eec75e186c79aabefa7da002bb979da1","head":{"label":"blixtra:blixtra/rkt-implement-image-list-full-flag","ref":"blixtra/rkt-implement-image-list-full-flag","sha":"827e1695eec75e186c79aabefa7da002bb979da1","user":{"login":"blixtra","id":115075,"avatar_url":"https://avatars.githubusercontent.com/u/115075?v=3","gravatar_id":"","url":"https://api.github.com/users/blixtra","html_url":"https://github.com/blixtra","followers_url":"https://api.github.com/users/blixtra/followers","following_url":"https://api.github.com/users/blixtra/following{/other_user}","gists_url":"https://api.github.com/users/blixtra/gists{/gist_id}","starred_url":"https://api.github.com/users/blixtra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blixtra/subscriptions","organizations_url":"https://api.github.com/users/blixtra/orgs","repos_url":"https://api.github.com/users/blixtra/repos","events_url":"https://api.github.com/users/blixtra/events{/privacy}","received_events_url":"https://api.github.com/users/blixtra/received_events","type":"User","site_admin":false},"repo":{"id":42307931,"name":"rkt","full_name":"blixtra/rkt","owner":{"login":"blixtra","id":115075,"avatar_url":"https://avatars.githubusercontent.com/u/115075?v=3","gravatar_id":"","url":"https://api.github.com/users/blixtra","html_url":"https://github.com/blixtra","followers_url":"https://api.github.com/users/blixtra/followers","following_url":"https://api.github.com/users/blixtra/following{/other_user}","gists_url":"https://api.github.com/users/blixtra/gists{/gist_id}","starred_url":"https://api.github.com/users/blixtra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blixtra/subscriptions","organizations_url":"https://api.github.com/users/blixtra/orgs","repos_url":"https://api.github.com/users/blixtra/repos","events_url":"https://api.github.com/users/blixtra/events{/privacy}","received_events_url":"https://api.github.com/users/blixtra/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/blixtra/rkt","description":"rkt is an App Container runtime for Linux","fork":true,"url":"https://api.github.com/repos/blixtra/rkt","forks_url":"https://api.github.com/repos/blixtra/rkt/forks","keys_url":"https://api.github.com/repos/blixtra/rkt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/blixtra/rkt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/blixtra/rkt/teams","hooks_url":"https://api.github.com/repos/blixtra/rkt/hooks","issue_events_url":"https://api.github.com/repos/blixtra/rkt/issues/events{/number}","events_url":"https://api.github.com/repos/blixtra/rkt/events","assignees_url":"https://api.github.com/repos/blixtra/rkt/assignees{/user}","branches_url":"https://api.github.com/repos/blixtra/rkt/branches{/branch}","tags_url":"https://api.github.com/repos/blixtra/rkt/tags","blobs_url":"https://api.github.com/repos/blixtra/rkt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/blixtra/rkt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/blixtra/rkt/git/refs{/sha}","trees_url":"https://api.github.com/repos/blixtra/rkt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/blixtra/rkt/statuses/{sha}","languages_url":"https://api.github.com/repos/blixtra/rkt/languages","stargazers_url":"https://api.github.com/repos/blixtra/rkt/stargazers","contributors_url":"https://api.github.com/repos/blixtra/rkt/contributors","subscribers_url":"https://api.github.com/repos/blixtra/rkt/subscribers","subscription_url":"https://api.github.com/repos/blixtra/rkt/subscription","commits_url":"https://api.github.com/repos/blixtra/rkt/commits{/sha}","git_commits_url":"https://api.github.com/repos/blixtra/rkt/git/commits{/sha}","comments_url":"https://api.github.com/repos/blixtra/rkt/comments{/number}","issue_comment_url":"https://api.github.com/repos/blixtra/rkt/issues/comments{/number}","contents_url":"https://api.github.com/repos/blixtra/rkt/contents/{+path}","compare_url":"https://api.github.com/repos/blixtra/rkt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/blixtra/rkt/merges","archive_url":"https://api.github.com/repos/blixtra/rkt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/blixtra/rkt/downloads","issues_url":"https://api.github.com/repos/blixtra/rkt/issues{/number}","pulls_url":"https://api.github.com/repos/blixtra/rkt/pulls{/number}","milestones_url":"https://api.github.com/repos/blixtra/rkt/milestones{/number}","notifications_url":"https://api.github.com/repos/blixtra/rkt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/blixtra/rkt/labels{/name}","releases_url":"https://api.github.com/repos/blixtra/rkt/releases{/id}","created_at":"2015-09-11T12:45:16Z","updated_at":"2015-09-11T12:45:17Z","pushed_at":"2015-09-25T11:58:25Z","git_url":"git://github.com/blixtra/rkt.git","ssh_url":"git@github.com:blixtra/rkt.git","clone_url":"https://github.com/blixtra/rkt.git","svn_url":"https://github.com/blixtra/rkt","homepage":"","size":7849,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"coreos:master","ref":"master","sha":"cb9f3151e3909119d297753fff77862eb93279a8","user":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"repo":{"id":26509369,"name":"rkt","full_name":"coreos/rkt","owner":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coreos/rkt","description":"rkt is an App Container runtime for Linux","fork":false,"url":"https://api.github.com/repos/coreos/rkt","forks_url":"https://api.github.com/repos/coreos/rkt/forks","keys_url":"https://api.github.com/repos/coreos/rkt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coreos/rkt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coreos/rkt/teams","hooks_url":"https://api.github.com/repos/coreos/rkt/hooks","issue_events_url":"https://api.github.com/repos/coreos/rkt/issues/events{/number}","events_url":"https://api.github.com/repos/coreos/rkt/events","assignees_url":"https://api.github.com/repos/coreos/rkt/assignees{/user}","branches_url":"https://api.github.com/repos/coreos/rkt/branches{/branch}","tags_url":"https://api.github.com/repos/coreos/rkt/tags","blobs_url":"https://api.github.com/repos/coreos/rkt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coreos/rkt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coreos/rkt/git/refs{/sha}","trees_url":"https://api.github.com/repos/coreos/rkt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coreos/rkt/statuses/{sha}","languages_url":"https://api.github.com/repos/coreos/rkt/languages","stargazers_url":"https://api.github.com/repos/coreos/rkt/stargazers","contributors_url":"https://api.github.com/repos/coreos/rkt/contributors","subscribers_url":"https://api.github.com/repos/coreos/rkt/subscribers","subscription_url":"https://api.github.com/repos/coreos/rkt/subscription","commits_url":"https://api.github.com/repos/coreos/rkt/commits{/sha}","git_commits_url":"https://api.github.com/repos/coreos/rkt/git/commits{/sha}","comments_url":"https://api.github.com/repos/coreos/rkt/comments{/number}","issue_comment_url":"https://api.github.com/repos/coreos/rkt/issues/comments{/number}","contents_url":"https://api.github.com/repos/coreos/rkt/contents/{+path}","compare_url":"https://api.github.com/repos/coreos/rkt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coreos/rkt/merges","archive_url":"https://api.github.com/repos/coreos/rkt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coreos/rkt/downloads","issues_url":"https://api.github.com/repos/coreos/rkt/issues{/number}","pulls_url":"https://api.github.com/repos/coreos/rkt/pulls{/number}","milestones_url":"https://api.github.com/repos/coreos/rkt/milestones{/number}","notifications_url":"https://api.github.com/repos/coreos/rkt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coreos/rkt/labels{/name}","releases_url":"https://api.github.com/repos/coreos/rkt/releases{/id}","created_at":"2014-11-11T23:13:18Z","updated_at":"2015-09-25T02:35:31Z","pushed_at":"2015-09-25T12:18:13Z","git_url":"git://github.com/coreos/rkt.git","ssh_url":"git@github.com:coreos/rkt.git","clone_url":"https://github.com/coreos/rkt.git","svn_url":"https://github.com/coreos/rkt","homepage":"","size":18471,"stargazers_count":4681,"watchers_count":4681,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":386,"mirror_url":null,"open_issues_count":172,"forks":386,"open_issues":172,"watchers":4681,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coreos/rkt/pulls/1455"},"html":{"href":"https://github.com/coreos/rkt/pull/1455"},"issue":{"href":"https://api.github.com/repos/coreos/rkt/issues/1455"},"comments":{"href":"https://api.github.com/repos/coreos/rkt/issues/1455/comments"},"review_comments":{"href":"https://api.github.com/repos/coreos/rkt/pulls/1455/comments"},"review_comment":{"href":"https://api.github.com/repos/coreos/rkt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coreos/rkt/pulls/1455/commits"},"statuses":{"href":"https://api.github.com/repos/coreos/rkt/statuses/827e1695eec75e186c79aabefa7da002bb979da1"}}}}