{"action":"created","comment":{"url":"https://api.github.com/repos/spf13/hugo/pulls/comments/54819184","id":54819184,"diff_hunk":"@@ -0,0 +1,314 @@\n+package commands\n+\n+import (\n+\t\"fmt\"\n+\t\"math\"\n+\t\"math/rand\"\n+\t\"os\"\n+\t\"path/filepath\"\n+\t\"strconv\"\n+\t\"strings\"\n+\t\"testing\"\n+\t\"time\"\n+\n+\t\"github.com/spf13/afero\"\n+\t\"github.com/spf13/cobra\"\n+\t\"github.com/spf13/hugo/helpers\"\n+\t\"github.com/spf13/hugo/hugofs\"\n+\t\"github.com/spf13/hugo/hugolib\"\n+\t\"github.com/spf13/viper\"\n+\t\"github.com/stretchr/testify/assert\"\n+)\n+\n+func clearConfigFile() {\n+\tviper.SetConfigFile(\"\")\n+\tcfgFile = \"\"\n+\tdestination = \"\"\n+\tsource = \"\"\n+\tbaseURL = \"\"\n+}\n+\n+func TestUserErrorCommandNewUserError(t *testing.T) {\n+\tviper.Reset()\n+\tdefer viper.Reset()\n+\texpectedUserError := commandError{\"test\\n\", true}\n+\tactualUserError := newUserError(\"test\")\n+\tassert.Equal(t, expectedUserError, actualUserError)\n+}\n+\n+func TestSystemErrorCommandNewSystemError(t *testing.T) {\n+\tviper.Reset()\n+\tdefer viper.Reset()\n+\texpectedSystemError := commandError{\"test\\n\", false}\n+\tactualSystemError := newSystemError(\"test\")\n+\tassert.Equal(t, expectedSystemError, actualSystemError)\n+}\n+\n+func TestUserErrorCommandNewFormattedUserError(t *testing.T) {\n+\tviper.Reset()\n+\tdefer viper.Reset()\n+\texpectedUserError := commandError{\"test:12\", true}\n+\tactualUserError := newUserErrorF(\"test:%d\", 12)\n+\tassert.Equal(t, expectedUserError, actualUserError)\n+}\n+\n+func TestSystemErrorCommandNewFormattedSystemError(t *testing.T) {\n+\tviper.Reset()\n+\tdefer viper.Reset()\n+\texpectedSystemError := commandError{\"test:12\", false}\n+\tactualSystemError := newSystemErrorF(\"test:%d\", 12)\n+\tassert.Equal(t, expectedSystemError, actualSystemError)\n+\tif actualSystemError != expectedSystemError {\n+\t\tt.Errorf(\"Actual (%v) returned command did not equal expected (%v) command.\", actualSystemError, expectedSystemError)\n+\t}\n+}\n+\n+func TestUserErrorReturnError(t *testing.T) {\n+\tviper.Reset()\n+\tdefer viper.Reset()\n+\tcError := commandError{\"test error\", false}\n+\texpectedError := \"test error\"\n+\tactualError := cError.Error()\n+\tassert.Equal(t, expectedError, actualError)\n+}\n+\n+func TestIsUserError(t *testing.T) {\n+\tviper.Reset()\n+\tdefer viper.Reset()\n+\tvar errors = []struct {\n+\t\terr error\n+\t}{\n+\t\t{fmt.Errorf(\"argument\")},\n+\t\t{fmt.Errorf(\"flag\")},\n+\t\t{fmt.Errorf(\"shorthand\")},\n+\t\t{commandError{\"test\", true}},\n+\t}\n+\n+\tfor _, v := range errors {\n+\t\tif !isUserError(v.err) {\n+\t\t\tt.Errorf(\"Error (%v) should have been flagged as a user error.\", v)\n+\t\t}\n+\t}\n+}\n+\n+func TestExecuteAddedCommands(t *testing.T) {\n+\tviper.Reset()\n+\tdefer viper.Reset()\n+\tdefer clearConfigFile()\n+\tvar defaultCommands = []struct {\n+\t\tcmd *cobra.Command\n+\t}{\n+\t\t{serverCmd},\n+\t\t{versionCmd},\n+\t\t{configCmd},\n+\t\t{checkCmd},\n+\t\t{benchmarkCmd},\n+\t\t{convertCmd},\n+\t\t{newCmd},\n+\t\t{listCmd},\n+\t\t{undraftCmd},\n+\t\t{importCmd},\n+\t\t{genCmd},\n+\t}\n+\n+\tr := rand.New(rand.NewSource(time.Now().UnixNano()))\n+\tblogSuffic := strconv.Itoa(r.Intn(math.MaxInt8))\n+\tbasepath := filepath.Join(os.TempDir(), \"blog\"+blogSuffic)\n+\tconfigPath := filepath.Join(basepath, \"config.toml\")\n+\thugofs.SourceFs = new(afero.OsFs)\n+\thugofs.SourceFs.MkdirAll(basepath, os.ModePerm|os.ModeDir)\n+\tpaths := []string{\n+\t\tfilepath.Join(basepath, \"public\"),\n+\t\tfilepath.Join(basepath, \"layouts\"),\n+\t\tfilepath.Join(basepath, \"content\"),\n+\t\tfilepath.Join(basepath, \"archetypes\"),\n+\t\tfilepath.Join(basepath, \"static\"),\n+\t\tfilepath.Join(basepath, \"data\"),\n+\t}\n+\n+\tfor _, path := range paths {\n+\t\thugofs.SourceFs.MkdirAll(path, os.ModePerm|os.ModeDir)\n+\t}\n+\n+\tfile, err := hugofs.SourceFs.Create(configPath)\n+\tif err != nil {\n+\t\tt.Error(err.Error())\n+\t}\n+\terr = hugofs.SourceFs.Chmod(configPath, os.ModeTemporary|os.ModePerm)\n+\tif err != nil {\n+\t\tt.Error(err.Error())\n+\t}\n+\n+\tbasicConfig := `\n+        contentdir = ` + strconv.Quote(paths[2]) + `\n+        layoutdir = ` + strconv.Quote(paths[1]) + `\n+        publishdir = ` + strconv.Quote(paths[0]) + `\n+        baseurl = \"http://localhost\"\n+        canonifyurls = true`\n+\n+\t_, err = file.WriteString(basicConfig)\n+\tif err != nil {\n+\t\tt.Error(err.Error())\n+\t}\n+\tcfgFile = configPath\n+\t// Workaround for go test -coverprofile=cover.out since viper parses command-line\n+\t// arguments.\n+\tif len(os.Args) > 1 {\n+\t\tos.Args = os.Args[:1]\n+\t}\n+\tExecute()\n+\tcommands := HugoCmd.Commands()\n+\n+\tfor _, dc := range defaultCommands {\n+\t\tif !containesCommand(dc.cmd, commands) {\n+\t\t\tt.Errorf(\"Default command (%v) was not contained in the list of default commands. List: %#v\", dc.cmd, commands)\n+\t\t}\n+\t}\n+\n+}\n+\n+func TestInitializeConfigSetsWorkingDirToSourceIfSet(t *testing.T) {\n+\tviper.Reset()\n+\tdefer viper.Reset()\n+\tdefer hugoCmdV.ResetCommands()\n+\tdefer hugoCmdV.ResetFlags()\n+\tdefer clearConfigFile()\n+\tr := rand.New(rand.NewSource(time.Now().UnixNano()))\n+\tblogSuffic := strconv.Itoa(r.Intn(math.MaxInt8))","path":"commands/hugo_test.go","position":177,"original_position":177,"commit_id":"74689912ab8aea7141d644686e13d11966b2bb43","original_commit_id":"74689912ab8aea7141d644686e13d11966b2bb43","user":{"login":"Skarlso","id":182850,"avatar_url":"https://avatars.githubusercontent.com/u/182850?v=3","gravatar_id":"","url":"https://api.github.com/users/Skarlso","html_url":"https://github.com/Skarlso","followers_url":"https://api.github.com/users/Skarlso/followers","following_url":"https://api.github.com/users/Skarlso/following{/other_user}","gists_url":"https://api.github.com/users/Skarlso/gists{/gist_id}","starred_url":"https://api.github.com/users/Skarlso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Skarlso/subscriptions","organizations_url":"https://api.github.com/users/Skarlso/orgs","repos_url":"https://api.github.com/users/Skarlso/repos","events_url":"https://api.github.com/users/Skarlso/events{/privacy}","received_events_url":"https://api.github.com/users/Skarlso/received_events","type":"User","site_admin":false},"body":"Yes. :-)","created_at":"2016-03-03T00:41:15Z","updated_at":"2016-03-03T00:41:15Z","html_url":"https://github.com/spf13/hugo/pull/1834#discussion_r54819184","pull_request_url":"https://api.github.com/repos/spf13/hugo/pulls/1834","_links":{"self":{"href":"https://api.github.com/repos/spf13/hugo/pulls/comments/54819184"},"html":{"href":"https://github.com/spf13/hugo/pull/1834#discussion_r54819184"},"pull_request":{"href":"https://api.github.com/repos/spf13/hugo/pulls/1834"}}},"pull_request":{"url":"https://api.github.com/repos/spf13/hugo/pulls/1834","id":58769993,"html_url":"https://github.com/spf13/hugo/pull/1834","diff_url":"https://github.com/spf13/hugo/pull/1834.diff","patch_url":"https://github.com/spf13/hugo/pull/1834.patch","issue_url":"https://api.github.com/repos/spf13/hugo/issues/1834","number":1834,"state":"open","locked":false,"title":"Increasing coverage for Command Package","user":{"login":"Skarlso","id":182850,"avatar_url":"https://avatars.githubusercontent.com/u/182850?v=3","gravatar_id":"","url":"https://api.github.com/users/Skarlso","html_url":"https://github.com/Skarlso","followers_url":"https://api.github.com/users/Skarlso/followers","following_url":"https://api.github.com/users/Skarlso/following{/other_user}","gists_url":"https://api.github.com/users/Skarlso/gists{/gist_id}","starred_url":"https://api.github.com/users/Skarlso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Skarlso/subscriptions","organizations_url":"https://api.github.com/users/Skarlso/orgs","repos_url":"https://api.github.com/users/Skarlso/repos","events_url":"https://api.github.com/users/Skarlso/events{/privacy}","received_events_url":"https://api.github.com/users/Skarlso/received_events","type":"User","site_admin":false},"body":"Begun to increase coverage in the command package. Starting with\r\nhugo.go.\r\n\r\n* Added hugo_test.go and started to increase coverage for Hugo command\r\n* Two minor tweaks to hugo.go in comment and conditional structure\r\n* Current coverage of hugo.go is at 49.5%\r\n* Most of the configuration initialization has been covered sofar\r\n* Larger parts uncovered remaining are: NewWatcher, getDirList and copyStatic","created_at":"2016-02-09T16:17:11Z","updated_at":"2016-03-03T00:41:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"953e0dc4b6bb03757ac985d626d9ce00dd289d7d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/spf13/hugo/pulls/1834/commits","review_comments_url":"https://api.github.com/repos/spf13/hugo/pulls/1834/comments","review_comment_url":"https://api.github.com/repos/spf13/hugo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spf13/hugo/issues/1834/comments","statuses_url":"https://api.github.com/repos/spf13/hugo/statuses/74689912ab8aea7141d644686e13d11966b2bb43","head":{"label":"Skarlso:commandtests","ref":"commandtests","sha":"74689912ab8aea7141d644686e13d11966b2bb43","user":{"login":"Skarlso","id":182850,"avatar_url":"https://avatars.githubusercontent.com/u/182850?v=3","gravatar_id":"","url":"https://api.github.com/users/Skarlso","html_url":"https://github.com/Skarlso","followers_url":"https://api.github.com/users/Skarlso/followers","following_url":"https://api.github.com/users/Skarlso/following{/other_user}","gists_url":"https://api.github.com/users/Skarlso/gists{/gist_id}","starred_url":"https://api.github.com/users/Skarlso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Skarlso/subscriptions","organizations_url":"https://api.github.com/users/Skarlso/orgs","repos_url":"https://api.github.com/users/Skarlso/repos","events_url":"https://api.github.com/users/Skarlso/events{/privacy}","received_events_url":"https://api.github.com/users/Skarlso/received_events","type":"User","site_admin":false},"repo":{"id":51378504,"name":"hugo","full_name":"Skarlso/hugo","owner":{"login":"Skarlso","id":182850,"avatar_url":"https://avatars.githubusercontent.com/u/182850?v=3","gravatar_id":"","url":"https://api.github.com/users/Skarlso","html_url":"https://github.com/Skarlso","followers_url":"https://api.github.com/users/Skarlso/followers","following_url":"https://api.github.com/users/Skarlso/following{/other_user}","gists_url":"https://api.github.com/users/Skarlso/gists{/gist_id}","starred_url":"https://api.github.com/users/Skarlso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Skarlso/subscriptions","organizations_url":"https://api.github.com/users/Skarlso/orgs","repos_url":"https://api.github.com/users/Skarlso/repos","events_url":"https://api.github.com/users/Skarlso/events{/privacy}","received_events_url":"https://api.github.com/users/Skarlso/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Skarlso/hugo","description":"A Fast and Flexible Static Site Generator built with love in GoLang","fork":true,"url":"https://api.github.com/repos/Skarlso/hugo","forks_url":"https://api.github.com/repos/Skarlso/hugo/forks","keys_url":"https://api.github.com/repos/Skarlso/hugo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Skarlso/hugo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Skarlso/hugo/teams","hooks_url":"https://api.github.com/repos/Skarlso/hugo/hooks","issue_events_url":"https://api.github.com/repos/Skarlso/hugo/issues/events{/number}","events_url":"https://api.github.com/repos/Skarlso/hugo/events","assignees_url":"https://api.github.com/repos/Skarlso/hugo/assignees{/user}","branches_url":"https://api.github.com/repos/Skarlso/hugo/branches{/branch}","tags_url":"https://api.github.com/repos/Skarlso/hugo/tags","blobs_url":"https://api.github.com/repos/Skarlso/hugo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Skarlso/hugo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Skarlso/hugo/git/refs{/sha}","trees_url":"https://api.github.com/repos/Skarlso/hugo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Skarlso/hugo/statuses/{sha}","languages_url":"https://api.github.com/repos/Skarlso/hugo/languages","stargazers_url":"https://api.github.com/repos/Skarlso/hugo/stargazers","contributors_url":"https://api.github.com/repos/Skarlso/hugo/contributors","subscribers_url":"https://api.github.com/repos/Skarlso/hugo/subscribers","subscription_url":"https://api.github.com/repos/Skarlso/hugo/subscription","commits_url":"https://api.github.com/repos/Skarlso/hugo/commits{/sha}","git_commits_url":"https://api.github.com/repos/Skarlso/hugo/git/commits{/sha}","comments_url":"https://api.github.com/repos/Skarlso/hugo/comments{/number}","issue_comment_url":"https://api.github.com/repos/Skarlso/hugo/issues/comments{/number}","contents_url":"https://api.github.com/repos/Skarlso/hugo/contents/{+path}","compare_url":"https://api.github.com/repos/Skarlso/hugo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Skarlso/hugo/merges","archive_url":"https://api.github.com/repos/Skarlso/hugo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Skarlso/hugo/downloads","issues_url":"https://api.github.com/repos/Skarlso/hugo/issues{/number}","pulls_url":"https://api.github.com/repos/Skarlso/hugo/pulls{/number}","milestones_url":"https://api.github.com/repos/Skarlso/hugo/milestones{/number}","notifications_url":"https://api.github.com/repos/Skarlso/hugo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Skarlso/hugo/labels{/name}","releases_url":"https://api.github.com/repos/Skarlso/hugo/releases{/id}","deployments_url":"https://api.github.com/repos/Skarlso/hugo/deployments","created_at":"2016-02-09T16:12:01Z","updated_at":"2016-02-09T16:12:02Z","pushed_at":"2016-02-12T14:19:52Z","git_url":"git://github.com/Skarlso/hugo.git","ssh_url":"git@github.com:Skarlso/hugo.git","clone_url":"https://github.com/Skarlso/hugo.git","svn_url":"https://github.com/Skarlso/hugo","homepage":"http://gohugo.io","size":25809,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"spf13:master","ref":"master","sha":"cc38a40f4e79369af22974129969732c4f4af4ba","user":{"login":"spf13","id":173412,"avatar_url":"https://avatars.githubusercontent.com/u/173412?v=3","gravatar_id":"","url":"https://api.github.com/users/spf13","html_url":"https://github.com/spf13","followers_url":"https://api.github.com/users/spf13/followers","following_url":"https://api.github.com/users/spf13/following{/other_user}","gists_url":"https://api.github.com/users/spf13/gists{/gist_id}","starred_url":"https://api.github.com/users/spf13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spf13/subscriptions","organizations_url":"https://api.github.com/users/spf13/orgs","repos_url":"https://api.github.com/users/spf13/repos","events_url":"https://api.github.com/users/spf13/events{/privacy}","received_events_url":"https://api.github.com/users/spf13/received_events","type":"User","site_admin":false},"repo":{"id":11180687,"name":"hugo","full_name":"spf13/hugo","owner":{"login":"spf13","id":173412,"avatar_url":"https://avatars.githubusercontent.com/u/173412?v=3","gravatar_id":"","url":"https://api.github.com/users/spf13","html_url":"https://github.com/spf13","followers_url":"https://api.github.com/users/spf13/followers","following_url":"https://api.github.com/users/spf13/following{/other_user}","gists_url":"https://api.github.com/users/spf13/gists{/gist_id}","starred_url":"https://api.github.com/users/spf13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spf13/subscriptions","organizations_url":"https://api.github.com/users/spf13/orgs","repos_url":"https://api.github.com/users/spf13/repos","events_url":"https://api.github.com/users/spf13/events{/privacy}","received_events_url":"https://api.github.com/users/spf13/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/spf13/hugo","description":"A Fast and Flexible Static Site Generator built with love in GoLang","fork":false,"url":"https://api.github.com/repos/spf13/hugo","forks_url":"https://api.github.com/repos/spf13/hugo/forks","keys_url":"https://api.github.com/repos/spf13/hugo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spf13/hugo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spf13/hugo/teams","hooks_url":"https://api.github.com/repos/spf13/hugo/hooks","issue_events_url":"https://api.github.com/repos/spf13/hugo/issues/events{/number}","events_url":"https://api.github.com/repos/spf13/hugo/events","assignees_url":"https://api.github.com/repos/spf13/hugo/assignees{/user}","branches_url":"https://api.github.com/repos/spf13/hugo/branches{/branch}","tags_url":"https://api.github.com/repos/spf13/hugo/tags","blobs_url":"https://api.github.com/repos/spf13/hugo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spf13/hugo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spf13/hugo/git/refs{/sha}","trees_url":"https://api.github.com/repos/spf13/hugo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spf13/hugo/statuses/{sha}","languages_url":"https://api.github.com/repos/spf13/hugo/languages","stargazers_url":"https://api.github.com/repos/spf13/hugo/stargazers","contributors_url":"https://api.github.com/repos/spf13/hugo/contributors","subscribers_url":"https://api.github.com/repos/spf13/hugo/subscribers","subscription_url":"https://api.github.com/repos/spf13/hugo/subscription","commits_url":"https://api.github.com/repos/spf13/hugo/commits{/sha}","git_commits_url":"https://api.github.com/repos/spf13/hugo/git/commits{/sha}","comments_url":"https://api.github.com/repos/spf13/hugo/comments{/number}","issue_comment_url":"https://api.github.com/repos/spf13/hugo/issues/comments{/number}","contents_url":"https://api.github.com/repos/spf13/hugo/contents/{+path}","compare_url":"https://api.github.com/repos/spf13/hugo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spf13/hugo/merges","archive_url":"https://api.github.com/repos/spf13/hugo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spf13/hugo/downloads","issues_url":"https://api.github.com/repos/spf13/hugo/issues{/number}","pulls_url":"https://api.github.com/repos/spf13/hugo/pulls{/number}","milestones_url":"https://api.github.com/repos/spf13/hugo/milestones{/number}","notifications_url":"https://api.github.com/repos/spf13/hugo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spf13/hugo/labels{/name}","releases_url":"https://api.github.com/repos/spf13/hugo/releases{/id}","deployments_url":"https://api.github.com/repos/spf13/hugo/deployments","created_at":"2013-07-04T15:26:26Z","updated_at":"2016-03-02T22:57:05Z","pushed_at":"2016-03-02T22:51:20Z","git_url":"git://github.com/spf13/hugo.git","ssh_url":"git@github.com:spf13/hugo.git","clone_url":"https://github.com/spf13/hugo.git","svn_url":"https://github.com/spf13/hugo","homepage":"http://gohugo.io","size":37400,"stargazers_count":8641,"watchers_count":8641,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1387,"mirror_url":null,"open_issues_count":286,"forks":1387,"open_issues":286,"watchers":8641,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spf13/hugo/pulls/1834"},"html":{"href":"https://github.com/spf13/hugo/pull/1834"},"issue":{"href":"https://api.github.com/repos/spf13/hugo/issues/1834"},"comments":{"href":"https://api.github.com/repos/spf13/hugo/issues/1834/comments"},"review_comments":{"href":"https://api.github.com/repos/spf13/hugo/pulls/1834/comments"},"review_comment":{"href":"https://api.github.com/repos/spf13/hugo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spf13/hugo/pulls/1834/commits"},"statuses":{"href":"https://api.github.com/repos/spf13/hugo/statuses/74689912ab8aea7141d644686e13d11966b2bb43"}}}}