Exemple #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)
	}
}
Exemple #2
0
// createJob adds a new job to the database.
func (p *pushCallback) createJob() error {
	if p.shouldRun() == false {
		log.Println("Not adding", p.repositoryURL(), p.branch())
		return nil
	}

	repo := database.GetRepository(p.repositoryURL())

	job := database.CreateJob(
		repo,
		p.branch(),
		p.commit(),
		p.commitURL(),
		p.name(),
		p.email(),
	)

	status := make(chan bool, 1)

	queueJob := runner.QueueJob{
		JobID:  job.ID,
		Status: status,
	}

	queueJob.Enqueue()

	if repo.StatusPR {
		<-status
		job = database.GetJob(job.ID)
		postStatus(job, repo, p.statusURL())
	}

	return nil
}
Exemple #3
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)
	}
}
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))
	}
}
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)
	}
}
Exemple #6
0
// viewRerunJob resets a job status and enqueues it agian.
func viewRerunJob(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	jobID, _ := strconv.Atoi(vars["jid"])

	old := database.GetJob(int64(jobID))
	job := database.CreateJob(
		&old.Repository,
		old.Branch,
		old.Commit,
		old.CommitURL,
		old.Name,
		old.Email,
	)

	queueJob := runner.QueueJob{
		JobID: job.ID,
	}

	queueJob.Enqueue()

	http.Redirect(w, r, "/", 302)
}