Example #1
0
func TestEmailSubject(t *testing.T) {
	repo, _ := database.CreateRepository("repo", "bar", "accessKey", false, false)
	job := database.CreateJob(repo, "branch", "1234", "commitURL", "foo", "bar")
	job.TasksDone()

	build := emailSubject(job, EventBuild)
	test := emailSubject(job, EventTest)
	deployStart := emailSubject(job, EventDeployStart)
	deployEnd := emailSubject(job, EventDeployEnd)

	if build != "repo/branch build" {
		t.Error("Wrong message", build)
	}

	if test != "repo/branch tests" {
		t.Error("Wrong message", test)
	}

	if deployStart != "repo/branch deployment started" {
		t.Error("Wrong message", deployStart)
	}

	if deployEnd != "repo/branch deploy success" {
		t.Error("Wrong message", deployEnd)
	}
}
Example #2
0
func TestNewStatus(t *testing.T) {
	database.NewInMemoryDatabase()
	repo, _ := database.CreateRepository("foo", "bar", "accessKey", false, false)
	job := database.CreateJob(repo, "branch", "commit", "commitURL", "name", "email")
	status := newStatus(job)

	if status.TargetURL != "/1" {
		t.Error("Wrong target URL", status.TargetURL)
	}
}
Example #3
0
func TestPayloadCampfire(t *testing.T) {
	repo, _ := database.CreateRepository("repo", "", "", false, false)
	job := database.CreateJob(repo, "branch", "bar", "commit URL", "name", "email")

	pay, err := payloadCampfire(job, EventBuild)

	if err != nil {
		t.Error(err.Error())
	}

	if !strings.Contains(string(pay), "repo") {
		t.Error("Wrong payload", string(pay))
	}
}
Example #4
0
func TestNewMessage(t *testing.T) {
	database.NewInMemoryDatabase()
	repo, _ := database.CreateRepository("foo", "baz", "accessKey", false, false)
	job := database.CreateJob(repo, "branch", "commit", "commitURL", "name", "email")

	msg := NewMessage(job, "foo")

	if msg.Status != database.JobStatusPending {
		t.Error("Wrong status", msg.Status)
	}

	if msg.RepositoryName != "foo" {
		t.Error("Wrong repository name", msg.RepositoryName)
	}
}
Example #5
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))
	}
}