adding mocks for Builder.setup()

This commit is contained in:
Brad Rydzewski
2014-03-14 11:52:24 -07:00
parent 3d4e3168b7
commit 6f8bbf1d04
3 changed files with 361 additions and 45 deletions

View File

@@ -210,50 +210,6 @@ func SetupFixtures() {
settings.Domain = "localhost"
database.SaveSettings(&settings)
/*
mux.HandleFunc("/repos/octocat/", func(w http.ResponseWriter, r *http.Request) {
switch {
case r.URL.Path == "/repos/octocat/notfound":
http.NotFound(w, r)
case r.URL.Path == "/repos/ocotcat/hookfail":
fmt.Fprint(w, `{"id":1296269,"name":"hookfail","full_name":"octocat/hookfail","owner":{"login":"octocat","id":583231,"avatar_url":"https://gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c?d=https%3A%2F%2Fidenticons.github.com%2Fb295bf8043975e176de44c2617751f8b.png&r=x","gravatar_id":"7194e8d48fa1d2b689f99443b767316c","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/octocat/hookfail","description":"This your first repo!","fork":false,"url":"https://api.github.com/repos/octocat/hookfail","forks_url":"https://api.github.com/repos/octocat/hookfail/forks","keys_url":"https://api.github.com/repos/octocat/hookfail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/octocat/hookfail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/octocat/hookfail/teams","hooks_url":"https://api.github.com/repos/octocat/hookfail/hooks","issue_events_url":"https://api.github.com/repos/octocat/hookfail/issues/events{/number}","events_url":"https://api.github.com/repos/octocat/hookfail/events","assignees_url":"https://api.github.com/repos/octocat/hookfail/assignees{/user}","branches_url":"https://api.github.com/repos/octocat/hookfail/branches{/branch}","tags_url":"https://api.github.com/repos/octocat/hookfail/tags","blobs_url":"https://api.github.com/repos/octocat/hookfail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/octocat/hookfail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/octocat/hookfail/git/refs{/sha}","trees_url":"https://api.github.com/repos/octocat/hookfail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/octocat/hookfail/statuses/{sha}","languages_url":"https://api.github.com/repos/octocat/hookfail/languages","stargazers_url":"https://api.github.com/repos/octocat/hookfail/stargazers","contributors_url":"https://api.github.com/repos/octocat/hookfail/contributors","subscribers_url":"https://api.github.com/repos/octocat/hookfail/subscribers","subscription_url":"https://api.github.com/repos/octocat/hookfail/subscription","commits_url":"https://api.github.com/repos/octocat/hookfail/commits{/sha}","git_commits_url":"https://api.github.com/repos/octocat/hookfail/git/commits{/sha}","comments_url":"https://api.github.com/repos/octocat/hookfail/comments{/number}","issue_comment_url":"https://api.github.com/repos/octocat/hookfail/issues/comments/{number}","contents_url":"https://api.github.com/repos/octocat/hookfail/contents/{+path}","compare_url":"https://api.github.com/repos/octocat/hookfail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/octocat/hookfail/merges","archive_url":"https://api.github.com/repos/octocat/hookfail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/octocat/hookfail/downloads","issues_url":"https://api.github.com/repos/octocat/hookfail/issues{/number}","pulls_url":"https://api.github.com/repos/octocat/hookfail/pulls{/number}","milestones_url":"https://api.github.com/repos/octocat/hookfail/milestones{/number}","notifications_url":"https://api.github.com/repos/octocat/hookfail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/octocat/hookfail/labels{/name}","releases_url":"https://api.github.com/repos/octocat/hookfail/releases{/id}","created_at":"2011-01-26T19:01:12Z","updated_at":"2014-01-14T20:21:44Z","pushed_at":"2012-03-06T23:06:51Z","git_url":"git://github.com/octocat/hookfail.git","ssh_url":"git@github.com:octocat/hookfail.git","clone_url":"https://github.com/octocat/hookfail.git","svn_url":"https://github.com/octocat/hookfail","homepage":"","size":263,"stargazers_count":1365,"watchers_count":1365,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":867,"mirror_url":null,"open_issues_count":87,"forks":867,"open_issues":87,"watchers":1365,"default_branch":"master","master_branch":"master","network_count":867,"subscribers_count":1396}`)
// ------------------------------------------------------------------------
// Repository that should fail to add an SSH key
case r.URL.Path == "/repos/ocotcat/keyfail":
fmt.Fprint(w, `{"id":1296269,"name":"keyfail","full_name":"octocat/keyfail","owner":{"login":"octocat","id":583231,"avatar_url":"https://gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c?d=https%3A%2F%2Fidenticons.github.com%2Fb295bf8043975e176de44c2617751f8b.png&r=x","gravatar_id":"7194e8d48fa1d2b689f99443b767316c","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/octocat/keyfail","description":"This your first repo!","fork":false,"url":"https://api.github.com/repos/octocat/keyfail","forks_url":"https://api.github.com/repos/octocat/keyfail/forks","keys_url":"https://api.github.com/repos/octocat/keyfail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/octocat/keyfail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/octocat/keyfail/teams","hooks_url":"https://api.github.com/repos/octocat/keyfail/hooks","issue_events_url":"https://api.github.com/repos/octocat/keyfail/issues/events{/number}","events_url":"https://api.github.com/repos/octocat/keyfail/events","assignees_url":"https://api.github.com/repos/octocat/keyfail/assignees{/user}","branches_url":"https://api.github.com/repos/octocat/keyfail/branches{/branch}","tags_url":"https://api.github.com/repos/octocat/keyfail/tags","blobs_url":"https://api.github.com/repos/octocat/keyfail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/octocat/keyfail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/octocat/keyfail/git/refs{/sha}","trees_url":"https://api.github.com/repos/octocat/keyfail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/octocat/keyfail/statuses/{sha}","languages_url":"https://api.github.com/repos/octocat/keyfail/languages","stargazers_url":"https://api.github.com/repos/octocat/keyfail/stargazers","contributors_url":"https://api.github.com/repos/octocat/keyfail/contributors","subscribers_url":"https://api.github.com/repos/octocat/keyfail/subscribers","subscription_url":"https://api.github.com/repos/octocat/keyfail/subscription","commits_url":"https://api.github.com/repos/octocat/keyfail/commits{/sha}","git_commits_url":"https://api.github.com/repos/octocat/keyfail/git/commits{/sha}","comments_url":"https://api.github.com/repos/octocat/keyfail/comments{/number}","issue_comment_url":"https://api.github.com/repos/octocat/keyfail/issues/comments/{number}","contents_url":"https://api.github.com/repos/octocat/keyfail/contents/{+path}","compare_url":"https://api.github.com/repos/octocat/keyfail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/octocat/keyfail/merges","archive_url":"https://api.github.com/repos/octocat/keyfail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/octocat/keyfail/downloads","issues_url":"https://api.github.com/repos/octocat/keyfail/issues{/number}","pulls_url":"https://api.github.com/repos/octocat/keyfail/pulls{/number}","milestones_url":"https://api.github.com/repos/octocat/keyfail/milestones{/number}","notifications_url":"https://api.github.com/repos/octocat/keyfail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/octocat/keyfail/labels{/name}","releases_url":"https://api.github.com/repos/octocat/keyfail/releases{/id}","created_at":"2011-01-26T19:01:12Z","updated_at":"2014-01-14T20:21:44Z","pushed_at":"2012-03-06T23:06:51Z","git_url":"git://github.com/octocat/keyfail.git","ssh_url":"git@github.com:octocat/keyfail.git","clone_url":"https://github.com/octocat/keyfail.git","svn_url":"https://github.com/octocat/keyfail","homepage":"","size":263,"stargazers_count":1365,"watchers_count":1365,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":867,"mirror_url":null,"open_issues_count":87,"forks":867,"open_issues":87,"watchers":1365,"default_branch":"master","master_branch":"master","network_count":867,"subscribers_count":1396}`)
case r.URL.Path == "/repos/octocat/hookfail/hooks":
http.Error(w, "Forbidden", http.StatusForbidden)
case r.URL.Path == "/repos/octocat/hookfail/hooks":
http.Error(w, "Forbidden", http.StatusForbidden)
}
})
// github repository not found
mux.HandleFunc("/repos/octocat/notfound", func(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
})
// user does not have permissions to create the hook
mux.HandleFunc("/repos/octocat/hookfail/hooks", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Forbidden", http.StatusForbidden)
})
// github repository found, but forbidden to create hooks
mux.HandleFunc("/repos/octocat/hookfail", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"id":1296269,"name":"hookfail","full_name":"octocat/hookfail","owner":{"login":"octocat","id":583231,"avatar_url":"https://gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c?d=https%3A%2F%2Fidenticons.github.com%2Fb295bf8043975e176de44c2617751f8b.png&r=x","gravatar_id":"7194e8d48fa1d2b689f99443b767316c","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/octocat/hookfail","description":"This your first repo!","fork":false,"url":"https://api.github.com/repos/octocat/hookfail","forks_url":"https://api.github.com/repos/octocat/hookfail/forks","keys_url":"https://api.github.com/repos/octocat/hookfail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/octocat/hookfail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/octocat/hookfail/teams","hooks_url":"https://api.github.com/repos/octocat/hookfail/hooks","issue_events_url":"https://api.github.com/repos/octocat/hookfail/issues/events{/number}","events_url":"https://api.github.com/repos/octocat/hookfail/events","assignees_url":"https://api.github.com/repos/octocat/hookfail/assignees{/user}","branches_url":"https://api.github.com/repos/octocat/hookfail/branches{/branch}","tags_url":"https://api.github.com/repos/octocat/hookfail/tags","blobs_url":"https://api.github.com/repos/octocat/hookfail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/octocat/hookfail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/octocat/hookfail/git/refs{/sha}","trees_url":"https://api.github.com/repos/octocat/hookfail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/octocat/hookfail/statuses/{sha}","languages_url":"https://api.github.com/repos/octocat/hookfail/languages","stargazers_url":"https://api.github.com/repos/octocat/hookfail/stargazers","contributors_url":"https://api.github.com/repos/octocat/hookfail/contributors","subscribers_url":"https://api.github.com/repos/octocat/hookfail/subscribers","subscription_url":"https://api.github.com/repos/octocat/hookfail/subscription","commits_url":"https://api.github.com/repos/octocat/hookfail/commits{/sha}","git_commits_url":"https://api.github.com/repos/octocat/hookfail/git/commits{/sha}","comments_url":"https://api.github.com/repos/octocat/hookfail/comments{/number}","issue_comment_url":"https://api.github.com/repos/octocat/hookfail/issues/comments/{number}","contents_url":"https://api.github.com/repos/octocat/hookfail/contents/{+path}","compare_url":"https://api.github.com/repos/octocat/hookfail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/octocat/hookfail/merges","archive_url":"https://api.github.com/repos/octocat/hookfail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/octocat/hookfail/downloads","issues_url":"https://api.github.com/repos/octocat/hookfail/issues{/number}","pulls_url":"https://api.github.com/repos/octocat/hookfail/pulls{/number}","milestones_url":"https://api.github.com/repos/octocat/hookfail/milestones{/number}","notifications_url":"https://api.github.com/repos/octocat/hookfail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/octocat/hookfail/labels{/name}","releases_url":"https://api.github.com/repos/octocat/hookfail/releases{/id}","created_at":"2011-01-26T19:01:12Z","updated_at":"2014-01-14T20:21:44Z","pushed_at":"2012-03-06T23:06:51Z","git_url":"git://github.com/octocat/hookfail.git","ssh_url":"git@github.com:octocat/hookfail.git","clone_url":"https://github.com/octocat/hookfail.git","svn_url":"https://github.com/octocat/hookfail","homepage":"","size":263,"stargazers_count":1365,"watchers_count":1365,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":867,"mirror_url":null,"open_issues_count":87,"forks":867,"open_issues":87,"watchers":1365,"default_branch":"master","master_branch":"master","network_count":867,"subscribers_count":1396}`)
})
// github repository found, but forbidden to create hooks
mux.HandleFunc("/repos/octocat/hookfail", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"id":1296269,"name":"hookfail","full_name":"octocat/hookfail","owner":{"login":"octocat","id":583231,"avatar_url":"https://gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c?d=https%3A%2F%2Fidenticons.github.com%2Fb295bf8043975e176de44c2617751f8b.png&r=x","gravatar_id":"7194e8d48fa1d2b689f99443b767316c","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/octocat/hookfail","description":"This your first repo!","fork":false,"url":"https://api.github.com/repos/octocat/hookfail","forks_url":"https://api.github.com/repos/octocat/hookfail/forks","keys_url":"https://api.github.com/repos/octocat/hookfail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/octocat/hookfail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/octocat/hookfail/teams","hooks_url":"https://api.github.com/repos/octocat/hookfail/hooks","issue_events_url":"https://api.github.com/repos/octocat/hookfail/issues/events{/number}","events_url":"https://api.github.com/repos/octocat/hookfail/events","assignees_url":"https://api.github.com/repos/octocat/hookfail/assignees{/user}","branches_url":"https://api.github.com/repos/octocat/hookfail/branches{/branch}","tags_url":"https://api.github.com/repos/octocat/hookfail/tags","blobs_url":"https://api.github.com/repos/octocat/hookfail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/octocat/hookfail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/octocat/hookfail/git/refs{/sha}","trees_url":"https://api.github.com/repos/octocat/hookfail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/octocat/hookfail/statuses/{sha}","languages_url":"https://api.github.com/repos/octocat/hookfail/languages","stargazers_url":"https://api.github.com/repos/octocat/hookfail/stargazers","contributors_url":"https://api.github.com/repos/octocat/hookfail/contributors","subscribers_url":"https://api.github.com/repos/octocat/hookfail/subscribers","subscription_url":"https://api.github.com/repos/octocat/hookfail/subscription","commits_url":"https://api.github.com/repos/octocat/hookfail/commits{/sha}","git_commits_url":"https://api.github.com/repos/octocat/hookfail/git/commits{/sha}","comments_url":"https://api.github.com/repos/octocat/hookfail/comments{/number}","issue_comment_url":"https://api.github.com/repos/octocat/hookfail/issues/comments/{number}","contents_url":"https://api.github.com/repos/octocat/hookfail/contents/{+path}","compare_url":"https://api.github.com/repos/octocat/hookfail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/octocat/hookfail/merges","archive_url":"https://api.github.com/repos/octocat/hookfail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/octocat/hookfail/downloads","issues_url":"https://api.github.com/repos/octocat/hookfail/issues{/number}","pulls_url":"https://api.github.com/repos/octocat/hookfail/pulls{/number}","milestones_url":"https://api.github.com/repos/octocat/hookfail/milestones{/number}","notifications_url":"https://api.github.com/repos/octocat/hookfail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/octocat/hookfail/labels{/name}","releases_url":"https://api.github.com/repos/octocat/hookfail/releases{/id}","created_at":"2011-01-26T19:01:12Z","updated_at":"2014-01-14T20:21:44Z","pushed_at":"2012-03-06T23:06:51Z","git_url":"git://github.com/octocat/hookfail.git","ssh_url":"git@github.com:octocat/hookfail.git","clone_url":"https://github.com/octocat/hookfail.git","svn_url":"https://github.com/octocat/hookfail","homepage":"","size":263,"stargazers_count":1365,"watchers_count":1365,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":867,"mirror_url":null,"open_issues_count":87,"forks":867,"open_issues":87,"watchers":1365,"default_branch":"master","master_branch":"master","network_count":867,"subscribers_count":1396}`)
})
*/
// -----------------------------------------------------------------------------------
// fixture to return a public repository and successfully
// create a commit hook.