{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/origin/pulls/comments/44494884","id":44494884,"diff_hunk":"@@ -0,0 +1,300 @@\n+#!/bin/bash\n+# This file ensures that the helper functions in util.sh behave as expected\n+\n+set -o errexit\n+set -o nounset\n+set -o pipefail\n+\n+OS_ROOT=$(dirname \"${BASH_SOURCE}\")/..\n+source \"${OS_ROOT}/hack/util.sh\"\n+source \"${OS_ROOT}/test/util.sh\"\n+os::log::install_errexit\n+\n+function echo_and_exit() {\n+\techo $1\n+\texit $2\n+}\n+\n+mkdir -p /tmp/openshift/origin/test/cmd/\n+JUNIT_OUTPUT_FILE=/tmp/openshift-cmd/junit_output.txt\n+\n+VERBOSE=1\n+\n+# positive tests\n+os::test::expect_success \"exit 0\"\n+\n+os::test::expect_failure \"exit 10\"\n+\n+os::test::expect_success_and_text \"echo_and_exit hello 0\" \"hello\"","path":"test/util_test.sh","position":28,"original_position":28,"commit_id":"9d66e51b6ea26d57a96dc5d66818a954ae96c72c","original_commit_id":"9d66e51b6ea26d57a96dc5d66818a954ae96c72c","user":{"login":"stevekuznetsov","id":7328370,"avatar_url":"https://avatars.githubusercontent.com/u/7328370?v=3","gravatar_id":"","url":"https://api.github.com/users/stevekuznetsov","html_url":"https://github.com/stevekuznetsov","followers_url":"https://api.github.com/users/stevekuznetsov/followers","following_url":"https://api.github.com/users/stevekuznetsov/following{/other_user}","gists_url":"https://api.github.com/users/stevekuznetsov/gists{/gist_id}","starred_url":"https://api.github.com/users/stevekuznetsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevekuznetsov/subscriptions","organizations_url":"https://api.github.com/users/stevekuznetsov/orgs","repos_url":"https://api.github.com/users/stevekuznetsov/repos","events_url":"https://api.github.com/users/stevekuznetsov/events{/privacy}","received_events_url":"https://api.github.com/users/stevekuznetsov/received_events","type":"User","site_admin":false},"body":"I tried for a very long time to get the second style to work, and I could not. It would always echo everything after that command. I'd appreciate help if you feel strongly about it. @Miciah didn't have a suggestion here.","created_at":"2015-11-11T02:14:40Z","updated_at":"2015-11-11T02:14:40Z","html_url":"https://github.com/openshift/origin/pull/5719#discussion_r44494884","pull_request_url":"https://api.github.com/repos/openshift/origin/pulls/5719","_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments/44494884"},"html":{"href":"https://github.com/openshift/origin/pull/5719#discussion_r44494884"},"pull_request":{"href":"https://api.github.com/repos/openshift/origin/pulls/5719"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/origin/pulls/5719","id":49762035,"html_url":"https://github.com/openshift/origin/pull/5719","diff_url":"https://github.com/openshift/origin/pull/5719.diff","patch_url":"https://github.com/openshift/origin/pull/5719.patch","issue_url":"https://api.github.com/repos/openshift/origin/issues/5719","number":5719,"state":"open","locked":false,"title":"added test-cmd test wrapper functions and tests","user":{"login":"stevekuznetsov","id":7328370,"avatar_url":"https://avatars.githubusercontent.com/u/7328370?v=3","gravatar_id":"","url":"https://api.github.com/users/stevekuznetsov","html_url":"https://github.com/stevekuznetsov","followers_url":"https://api.github.com/users/stevekuznetsov/followers","following_url":"https://api.github.com/users/stevekuznetsov/following{/other_user}","gists_url":"https://api.github.com/users/stevekuznetsov/gists{/gist_id}","starred_url":"https://api.github.com/users/stevekuznetsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevekuznetsov/subscriptions","organizations_url":"https://api.github.com/users/stevekuznetsov/orgs","repos_url":"https://api.github.com/users/stevekuznetsov/repos","events_url":"https://api.github.com/users/stevekuznetsov/events{/privacy}","received_events_url":"https://api.github.com/users/stevekuznetsov/received_events","type":"User","site_admin":false},"body":"I've added the following high-level wrapper functions for tests and a test file that ensures correct function:\r\n\r\n* `expect_{success,failure} $cmd` - run `$cmd` and expect a `{0,1}` result code\r\n* `expect_{success,failure}_and_text $cmd $text` - run `$cmd` and expect a `{0,1}` result code as well as `$text` in the output \r\n* `expect_{success,failure}_and_not_text $cmd $text` - run `$cmd` and expect a `{0,1}` result code as well as the absence of `$text` in the output \r\n\r\nNon-`1` result codes can be covered with more general test functions:\r\n* `expect_code  $cmd $code` - run `$cmd` and expect `$code`\r\n* `expect_code_and_text $cmd $code $text` - run `$cmd` and expect `$code` as well as `$text` in the output\r\n* `expect_code_and_not_text $cmd $code $text` - run `$cmd` and expect `$code` as well as the absence of `$text` in the output\r\n\r\nAll `$text` tests are done using `grep -E`, with negated searches using `-v`. All test wrapper functions honor `VERBOSE=1` in order to always print the output of the test, otherwise output is only printed on a failure.\r\n\r\nWe can remove the test suite for these wrappers. It's not pretty or optimized but was useful when writing them. I'd appreciate feedback on where these utility functions should live, currently I have them in `test/cmd/util.sh`\r\n\r\nBegins to address https://github.com/openshift/origin/issues/4929. We can use the following translations:\r\n\r\n| Original Construct              | Wrapper Function To Use                                                                                      |\r\n|-----------------------------------|------------------------------------------------------------------------------------------------------|\r\n| `cmd`                                  | `expect_success $cmd`                                                                                         |\r\n| `cmd | grep $text`               |  `expect_{success,failure}_and_text  $cmd $text` :exclamation:                           |\r\n| `[ $( $cmd | grep $text ) ]`   |   \"                                                                                                                           |\r\n| `[ $( $cmd ) ]`                      |  `expect_{success,failure}_and_text  $cmd \".\"` :exclamation: :question:               |\r\n| `[ -n $( $cmd ) ]`                  |  \"                                                                                                                            |\r\n| `[ ! $( $cmd | grep $text ) ]` | `expect_{success,failure}_and_not_text $cmd $text`:exclamation:                       |\r\n| `[ ! $( $cmd ) ]`                    | `expect_{success,failure}_and_not_text $cmd \".\"` :exclamation: :grey_question: |\r\n| `[ -z $( $cmd ) ]`                  |  \"                                                                                                                             |\r\n\r\n:exclamation: This will be difficult as currently the return code of `$cmd` is masked.\r\n:question: Currently I believe this is testing that the output of this to `stdout` is not null. Is this what we really want?\r\n:grey_question: Currently I believe this is testing that the output of this to `stdout` is null. Is this what we really want?\r\n\r\n/cc @deads2k @liggitt @smarterclayton \r\n\r\n","created_at":"2015-11-04T23:30:03Z","updated_at":"2015-11-11T02:14:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b886b65d36877a110006d4aa44a9da8540001c02","assignee":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/openshift/origin/milestones/10","html_url":"https://github.com/openshift/origin/milestones/1.1.1","labels_url":"https://api.github.com/repos/openshift/origin/milestones/10/labels","id":1394546,"number":10,"title":"1.1.1","description":"","creator":{"login":"smarterclayton","id":1163175,"avatar_url":"https://avatars.githubusercontent.com/u/1163175?v=3","gravatar_id":"","url":"https://api.github.com/users/smarterclayton","html_url":"https://github.com/smarterclayton","followers_url":"https://api.github.com/users/smarterclayton/followers","following_url":"https://api.github.com/users/smarterclayton/following{/other_user}","gists_url":"https://api.github.com/users/smarterclayton/gists{/gist_id}","starred_url":"https://api.github.com/users/smarterclayton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smarterclayton/subscriptions","organizations_url":"https://api.github.com/users/smarterclayton/orgs","repos_url":"https://api.github.com/users/smarterclayton/repos","events_url":"https://api.github.com/users/smarterclayton/events{/privacy}","received_events_url":"https://api.github.com/users/smarterclayton/received_events","type":"User","site_admin":false},"open_issues":35,"closed_issues":0,"state":"open","created_at":"2015-11-04T22:47:05Z","updated_at":"2015-11-10T21:00:40Z","due_on":"2015-12-09T05:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/openshift/origin/pulls/5719/commits","review_comments_url":"https://api.github.com/repos/openshift/origin/pulls/5719/comments","review_comment_url":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/origin/issues/5719/comments","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/9d66e51b6ea26d57a96dc5d66818a954ae96c72c","head":{"label":"stevekuznetsov:skuznets/refactor-test-cmd","ref":"skuznets/refactor-test-cmd","sha":"9d66e51b6ea26d57a96dc5d66818a954ae96c72c","user":{"login":"stevekuznetsov","id":7328370,"avatar_url":"https://avatars.githubusercontent.com/u/7328370?v=3","gravatar_id":"","url":"https://api.github.com/users/stevekuznetsov","html_url":"https://github.com/stevekuznetsov","followers_url":"https://api.github.com/users/stevekuznetsov/followers","following_url":"https://api.github.com/users/stevekuznetsov/following{/other_user}","gists_url":"https://api.github.com/users/stevekuznetsov/gists{/gist_id}","starred_url":"https://api.github.com/users/stevekuznetsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevekuznetsov/subscriptions","organizations_url":"https://api.github.com/users/stevekuznetsov/orgs","repos_url":"https://api.github.com/users/stevekuznetsov/repos","events_url":"https://api.github.com/users/stevekuznetsov/events{/privacy}","received_events_url":"https://api.github.com/users/stevekuznetsov/received_events","type":"User","site_admin":false},"repo":{"id":35963136,"name":"origin","full_name":"stevekuznetsov/origin","owner":{"login":"stevekuznetsov","id":7328370,"avatar_url":"https://avatars.githubusercontent.com/u/7328370?v=3","gravatar_id":"","url":"https://api.github.com/users/stevekuznetsov","html_url":"https://github.com/stevekuznetsov","followers_url":"https://api.github.com/users/stevekuznetsov/followers","following_url":"https://api.github.com/users/stevekuznetsov/following{/other_user}","gists_url":"https://api.github.com/users/stevekuznetsov/gists{/gist_id}","starred_url":"https://api.github.com/users/stevekuznetsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevekuznetsov/subscriptions","organizations_url":"https://api.github.com/users/stevekuznetsov/orgs","repos_url":"https://api.github.com/users/stevekuznetsov/repos","events_url":"https://api.github.com/users/stevekuznetsov/events{/privacy}","received_events_url":"https://api.github.com/users/stevekuznetsov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stevekuznetsov/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":true,"url":"https://api.github.com/repos/stevekuznetsov/origin","forks_url":"https://api.github.com/repos/stevekuznetsov/origin/forks","keys_url":"https://api.github.com/repos/stevekuznetsov/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stevekuznetsov/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stevekuznetsov/origin/teams","hooks_url":"https://api.github.com/repos/stevekuznetsov/origin/hooks","issue_events_url":"https://api.github.com/repos/stevekuznetsov/origin/issues/events{/number}","events_url":"https://api.github.com/repos/stevekuznetsov/origin/events","assignees_url":"https://api.github.com/repos/stevekuznetsov/origin/assignees{/user}","branches_url":"https://api.github.com/repos/stevekuznetsov/origin/branches{/branch}","tags_url":"https://api.github.com/repos/stevekuznetsov/origin/tags","blobs_url":"https://api.github.com/repos/stevekuznetsov/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stevekuznetsov/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stevekuznetsov/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/stevekuznetsov/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stevekuznetsov/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/stevekuznetsov/origin/languages","stargazers_url":"https://api.github.com/repos/stevekuznetsov/origin/stargazers","contributors_url":"https://api.github.com/repos/stevekuznetsov/origin/contributors","subscribers_url":"https://api.github.com/repos/stevekuznetsov/origin/subscribers","subscription_url":"https://api.github.com/repos/stevekuznetsov/origin/subscription","commits_url":"https://api.github.com/repos/stevekuznetsov/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/stevekuznetsov/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/stevekuznetsov/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/stevekuznetsov/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/stevekuznetsov/origin/contents/{+path}","compare_url":"https://api.github.com/repos/stevekuznetsov/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stevekuznetsov/origin/merges","archive_url":"https://api.github.com/repos/stevekuznetsov/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stevekuznetsov/origin/downloads","issues_url":"https://api.github.com/repos/stevekuznetsov/origin/issues{/number}","pulls_url":"https://api.github.com/repos/stevekuznetsov/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/stevekuznetsov/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/stevekuznetsov/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stevekuznetsov/origin/labels{/name}","releases_url":"https://api.github.com/repos/stevekuznetsov/origin/releases{/id}","created_at":"2015-05-20T17:28:25Z","updated_at":"2015-05-20T17:28:28Z","pushed_at":"2015-11-10T22:21:16Z","git_url":"git://github.com/stevekuznetsov/origin.git","ssh_url":"git@github.com:stevekuznetsov/origin.git","clone_url":"https://github.com/stevekuznetsov/origin.git","svn_url":"https://github.com/stevekuznetsov/origin","homepage":"http://www.openshift.org","size":179687,"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":"openshift:master","ref":"master","sha":"0bb48854f3de179191dc85a0f69d8247eda67d3b","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":22442668,"name":"origin","full_name":"openshift/origin","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":false,"url":"https://api.github.com/repos/openshift/origin","forks_url":"https://api.github.com/repos/openshift/origin/forks","keys_url":"https://api.github.com/repos/openshift/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/origin/teams","hooks_url":"https://api.github.com/repos/openshift/origin/hooks","issue_events_url":"https://api.github.com/repos/openshift/origin/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/origin/events","assignees_url":"https://api.github.com/repos/openshift/origin/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/origin/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/origin/tags","blobs_url":"https://api.github.com/repos/openshift/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/origin/languages","stargazers_url":"https://api.github.com/repos/openshift/origin/stargazers","contributors_url":"https://api.github.com/repos/openshift/origin/contributors","subscribers_url":"https://api.github.com/repos/openshift/origin/subscribers","subscription_url":"https://api.github.com/repos/openshift/origin/subscription","commits_url":"https://api.github.com/repos/openshift/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/origin/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/origin/merges","archive_url":"https://api.github.com/repos/openshift/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/origin/downloads","issues_url":"https://api.github.com/repos/openshift/origin/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/origin/labels{/name}","releases_url":"https://api.github.com/repos/openshift/origin/releases{/id}","created_at":"2014-07-30T20:04:05Z","updated_at":"2015-11-10T23:44:20Z","pushed_at":"2015-11-11T00:25:10Z","git_url":"git://github.com/openshift/origin.git","ssh_url":"git@github.com:openshift/origin.git","clone_url":"https://github.com/openshift/origin.git","svn_url":"https://github.com/openshift/origin","homepage":"http://www.openshift.org","size":300492,"stargazers_count":799,"watchers_count":799,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":495,"mirror_url":null,"open_issues_count":679,"forks":495,"open_issues":679,"watchers":799,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/5719"},"html":{"href":"https://github.com/openshift/origin/pull/5719"},"issue":{"href":"https://api.github.com/repos/openshift/origin/issues/5719"},"comments":{"href":"https://api.github.com/repos/openshift/origin/issues/5719/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/origin/pulls/5719/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/origin/pulls/5719/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/origin/statuses/9d66e51b6ea26d57a96dc5d66818a954ae96c72c"}}}}