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

@ -474,7 +474,7 @@ func (b *Builder) writeBuildScript(dir string) error {
f.WriteEnv("DRONE_PR", b.Repo.PR)
f.WriteEnv("DRONE_BUILD_DIR", b.Repo.Dir)
// add /etc/hosts entries
// add /etc/hosts entries
for _, mapping := range b.Build.Hosts {
f.WriteHost(mapping)
}

360
pkg/build/build_test.go Normal file
View file

@ -0,0 +1,360 @@
package build
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"testing"
"github.com/drone/drone/pkg/build/buildfile"
"github.com/drone/drone/pkg/build/docker"
"github.com/drone/drone/pkg/build/proxy"
"github.com/drone/drone/pkg/build/repo"
"github.com/drone/drone/pkg/build/script"
)
var (
// mux is the HTTP request multiplexer used with the test server.
mux *http.ServeMux
// server is a test HTTP server used to provide mock API responses.
server *httptest.Server
// docker client
client *docker.Client
)
// setup a mock docker client for testing purposes. This will use
// a test http server that can return mock responses to the docker client.
func setup() {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
url, _ := url.Parse(server.URL)
url.Scheme = "tcp"
os.Setenv("DOCKER_HOST", url.String())
client = docker.New()
}
func teardown() {
server.Close()
}
// TestSetup will test our ability to successfully create a Docker
// image for the build.
func TestSetup(t *testing.T) {
setup()
defer teardown()
// Handles a request to inspect the Go 1.2 image
// This will return a dummy image ID, so that the system knows
// the build image exists, and doens't need to be downloaded.
mux.HandleFunc("/v1.9/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) {
body := `[{ "id": "7bf9ce0ffb7236ca68da0f9fed0e1682053b393db3c724ff3c5a4e8c0793b34c" }]`
w.Write([]byte(body))
})
// Handles a request to create the build image, with the build
// script injected. This will return a dummy stream.
mux.HandleFunc("/v1.9/build", func(w http.ResponseWriter, r *http.Request) {
body := `{"stream":"Step 1..."}`
w.Write([]byte(body))
})
// Handles a request to inspect the newly created build image. Note
// that we are doing a "wildcard" url match here, since the name of
// the image will be random. This will return a dummy image ID
// to confirm the build image was created successfully.
mux.HandleFunc("/v1.9/images/", func(w http.ResponseWriter, r *http.Request) {
body := `{ "id": "7bf9ce0ffb7236ca68da0f9fed0e1682053b393db3c724ff3c5a4e8c0793b34c" }`
w.Write([]byte(body))
})
b := Builder{}
b.Repo = &repo.Repo{}
b.Repo.Path = "git://github.com/drone/drone.git"
b.Build = &script.Build{}
b.Build.Image = "go1.2"
b.dockerClient = client
if err := b.setup(); err != nil {
t.Errorf("Expected success, got %s", err)
}
// verify the Image is being correctly set
if b.image == nil {
t.Errorf("Expected image not nil")
}
expectedID := "7bf9ce0ffb7236ca68da0f9fed0e1682053b393db3c724ff3c5a4e8c0793b34c"
if b.image.ID != expectedID {
t.Errorf("Expected image.ID %s, got %s", expectedID, b.image.ID)
}
}
// Expected behavior is that a build script with no docker image
// specified will thrown an error.
func TestSetupEmptyImage(t *testing.T) {
b := Builder{Build: &script.Build{}}
var got, want = b.setup(), "Error: missing Docker image"
if got == nil || got.Error() != want {
t.Errorf("Expected error %s, got %s", want, got)
}
}
// Expected behavior is that a build script with an unknown
// service (ie mysql)
func TestSetupUnknownService(t *testing.T) {
b := Builder{}
b.Repo = &repo.Repo{}
b.Repo.Path = "git://github.com/drone/drone.git"
b.Build = &script.Build{}
b.Build.Image = "go1.2"
b.Build.Services = append(b.Build.Services, "not-found")
var got, want = b.setup(), "Error: Invalid or unknown service not-found"
if got == nil || got.Error() != want {
t.Errorf("Expected error %s, got %s", want, got)
}
}
func TestSetupErrorRunDaemonPorts(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1.9/containers/create", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
})
b := Builder{}
b.Repo = &repo.Repo{}
b.Repo.Path = "git://github.com/drone/drone.git"
b.Build = &script.Build{}
b.Build.Image = "go1.2"
b.Build.Services = append(b.Build.Services, "mysql")
b.dockerClient = client
var got, want = b.setup(), docker.ErrBadRequest
if got == nil || got != want {
t.Errorf("Expected error %s, got %s", want, got)
}
}
func TestSetupErrorServiceInspect(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1.9/containers/create", func(w http.ResponseWriter, r *http.Request) {
body := `{ "Id":"e90e34656806", "Warnings":[] }`
w.Write([]byte(body))
})
mux.HandleFunc("/v1.9/containers/e90e34656806/start", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
mux.HandleFunc("/v1.9/containers/e90e34656806/json", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
})
b := Builder{}
b.Repo = &repo.Repo{}
b.Repo.Path = "git://github.com/drone/drone.git"
b.Build = &script.Build{}
b.Build.Image = "go1.2"
b.Build.Services = append(b.Build.Services, "mysql")
b.dockerClient = client
var got, want = b.setup(), docker.ErrBadRequest
if got == nil || got != want {
t.Errorf("Expected error %s, got %s", want, got)
}
}
func TestSetupErrorImagePull(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1.9/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
})
mux.HandleFunc("/v1.9/images/create", func(w http.ResponseWriter, r *http.Request) {
// validate ?fromImage=bradrydzewski/go&tag=1.2
w.WriteHeader(http.StatusBadRequest)
})
b := Builder{}
b.Repo = &repo.Repo{}
b.Repo.Path = "git://github.com/drone/drone.git"
b.Build = &script.Build{}
b.Build.Image = "go1.2"
b.dockerClient = client
var got, want = b.setup(), docker.ErrBadRequest
if got == nil || got != want {
t.Errorf("Expected error %s, got %s", want, got)
}
}
func TestSetupErrorBuild(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1.9/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) {
body := `[{ "id": "7bf9ce0ffb7236ca68da0f9fed0e1682053b393db3c724ff3c5a4e8c0793b34c" }]`
w.Write([]byte(body))
})
mux.HandleFunc("/v1.9/build", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
})
b := Builder{}
b.Repo = &repo.Repo{}
b.Repo.Path = "git://github.com/drone/drone.git"
b.Build = &script.Build{}
b.Build.Image = "go1.2"
b.dockerClient = client
var got, want = b.setup(), docker.ErrBadRequest
if got == nil || got != want {
t.Errorf("Expected error %s, got %s", want, got)
}
}
func TestSetupErrorBuildInspect(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1.9/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) {
body := `[{ "id": "7bf9ce0ffb7236ca68da0f9fed0e1682053b393db3c724ff3c5a4e8c0793b34c" }]`
w.Write([]byte(body))
})
mux.HandleFunc("/v1.9/build", func(w http.ResponseWriter, r *http.Request) {
body := `{"stream":"Step 1..."}`
w.Write([]byte(body))
})
mux.HandleFunc("/v1.9/images/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
})
b := Builder{}
b.Repo = &repo.Repo{}
b.Repo.Path = "git://github.com/drone/drone.git"
b.Build = &script.Build{}
b.Build.Image = "go1.2"
b.dockerClient = client
var got, want = b.setup(), docker.ErrBadRequest
if got == nil || got != want {
t.Errorf("Expected error %s, got %s", want, got)
}
}
func TestTeardown(t *testing.T) {}
func TestTeardownContainerFail(t *testing.T) {}
func TestTeardownImageFail(t *testing.T) {}
func TestWriteIdentifyFile(t *testing.T) {
// temporary directory to store file
dir, _ := ioutil.TempDir("", "drone-test-")
defer os.RemoveAll(dir)
b := Builder{}
b.Key = []byte("ssh-rsa AAA...")
b.writeIdentifyFile(dir)
// persist a dummy id_rsa keyfile to disk
keyfile, err := ioutil.ReadFile(filepath.Join(dir, "id_rsa"))
if err != nil {
t.Errorf("Expected id_rsa file saved to disk")
}
if string(keyfile) != string(b.Key) {
t.Errorf("Expected id_rsa value saved as %s, got %s", b.Key, keyfile)
}
}
func TestWriteProxyScript(t *testing.T) {
// temporary directory to store file
dir, _ := ioutil.TempDir("", "drone-test-")
defer os.RemoveAll(dir)
// fake service container that we'll assume was part of the yaml
// and should be attached to the build container.
c := docker.Container{
NetworkSettings: &docker.NetworkSettings{
IPAddress: "172.1.4.5",
Ports: map[docker.Port][]docker.PortBinding{
docker.NewPort("tcp", "3306"): nil,
},
},
}
// this should generate the following proxy file
p := proxy.Proxy{}
p.Set("3306", "172.1.4.5")
want := p.String()
b := Builder{}
b.services = append(b.services, &c)
b.writeProxyScript(dir)
// persist a dummy proxy script to disk
got, err := ioutil.ReadFile(filepath.Join(dir, "proxy.sh"))
if err != nil {
t.Errorf("Expected proxy.sh file saved to disk")
}
if string(got) != want {
t.Errorf("Expected proxy.sh value saved as %s, got %s", want, got)
}
}
func TestWriteBuildScript(t *testing.T) {
// temporary directory to store file
dir, _ := ioutil.TempDir("", "drone-test-")
defer os.RemoveAll(dir)
b := Builder{}
b.Build = &script.Build{
Hosts: []string{"127.0.0.1"}}
b.Repo = &repo.Repo{
Path: "git://github.com/drone/drone.git",
Branch: "master",
Commit: "e7e046b35",
PR: "123",
Dir: "/var/cache/drone/github.com/drone/drone"}
b.writeBuildScript(dir)
// persist a dummy build script to disk
script, err := ioutil.ReadFile(filepath.Join(dir, "drone"))
if err != nil {
t.Errorf("Expected id_rsa file saved to disk")
}
f := buildfile.New()
f.WriteEnv("CI", "true")
f.WriteEnv("DRONE", "true")
f.WriteEnv("DRONE_BRANCH", "master")
f.WriteEnv("DRONE_COMMIT", "e7e046b35")
f.WriteEnv("DRONE_PR", "123")
f.WriteEnv("DRONE_BUILD_DIR", "/var/cache/drone/github.com/drone/drone")
f.WriteHost("127.0.0.1")
f.WriteCmd("git clone --depth=0 --recursive --branch=master git://github.com/drone/drone.git /var/cache/drone/github.com/drone/drone")
f.WriteCmd("git fetch origin +refs/pull/123/head:refs/remotes/origin/pr/123")
f.WriteCmd("git checkout -qf -b pr/123 origin/pr/123")
if string(script) != f.String() {
t.Errorf("Expected build script value saved as %s, got %s", f.String(), script)
}
}

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.