Esempio n. 1
0
func TestPushCreateJob(t *testing.T) {
	database.NewInMemoryDatabase()
	database.CreateRepository("https://github.com/fallenhitokiri/pushtest", "bar", "accessKey", false, false)
	payload := []byte(`{ "ref":"refs/heads/master", "after":"2c7f7accbcf73b7b4c98ee7e1f213eb46a885042", "before":"b369a904428a1d5d671e3f740443590d3db55fb0", "created":false, "deleted":false, "forced":false, "compare":"https://github.com/fallenhitokiri/pushtest/compare/b369a904428a...2c7f7accbcf7", "commits":[ { "id":"2c7f7accbcf73b7b4c98ee7e1f213eb46a885042", "distinct":true, "message":"asdf", "timestamp":"2014-04-27T11:53:14+02:00", "url":"https://github.com/fallenhitokiri/pushtest/commit/2c7f7accbcf73b7b4c98ee7e1f213eb46a885042", "author": { "name":"Timo Zimmermann", "email":"*****@*****.**", "username":"******" }, "committer":{ "name":"Timo Zimmermann", "email":"*****@*****.**", "username":"******" }, "added":[ "test2.md" ], "removed": [ ], "modified": [ ] } ], "head_commit": { "id":"2c7f7accbcf73b7b4c98ee7e1f213eb46a885042", "distinct":true, "message":"asdf", "timestamp":"2014-04-27T11:53:14+02:00", "url":"https://github.com/fallenhitokiri/pushtest/commit/2c7f7accbcf73b7b4c98ee7e1f213eb46a885042", "author": { "name":"Timo Zimmermann", "email":"*****@*****.**", "username":"******" }, "committer": { "name":"Timo Zimmermann", "email":"*****@*****.**", "username":"******" }, "added": [ "test2.md" ], "removed":[ ], "modified":[ ] }, "repository":{ "id":19200766, "name":"pushtest", "url":"https://github.com/fallenhitokiri/pushtest", "description":"nothing to see here", "watchers":0, "stargazers":0, "forks":0, "fork":false, "size":0, "owner":{ "name":"fallenhitokiri", "email":"*****@*****.**" }, "private":false, "open_issues":0, "has_issues":true, "has_downloads":true, "has_wiki":true, "created_at":1398591886, "pushed_at":1398592401, "master_branch":"master" }, "pusher": { "name":"fallenhitokiri", "email":"*****@*****.**"} }`)
	var cb pushCallback
	json.Unmarshal(payload, &cb)

	cb.createJob()
	if len(database.GetJobs(0, 10)) != 1 {
		t.Error("Wrong job count", database.GetJobs(0, 10))
	}

	cb.Deleted = true
	cb.createJob()
	if len(database.GetJobs(0, 10)) != 1 {
		t.Error("Wrong job count", database.GetJobs(0, 10))
	}
}
Esempio n. 2
0
// viewListJobs shows a paginated list of all jobs.
func viewListJobs(w http.ResponseWriter, r *http.Request) {
	template := "job/list.html"
	ctx := make(responseContext)

	offset := 0
	paramOffset := r.URL.Query().Get("offset")

	if len(paramOffset) > 0 {
		offset = stringToInt(paramOffset)
	}

	ctx["jobs"] = database.GetJobs(offset, limit)

	prev, next, first := previousNextNumber(offset)

	ctx["previous_offset"] = prev
	ctx["next_offset"] = next
	ctx["first_page"] = first

	render(w, r, template, ctx)
}