Skip to content

Commit

Permalink
Merge pull request #69 from AishwaryaRK/master
Browse files Browse the repository at this point in the history
[Aishwarya|Jenson] fix 404 bug of job execution status on waiting state
  • Loading branch information
jensoncs authored Jan 24, 2019
2 parents ed84fe9 + 608e807 commit ecb250c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion proctord/jobs/execution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func (handler *executionHandler) Status() http.HandlerFunc {

func (handler *executionHandler) Handle() http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
jobsExecutionAuditLog := &postgres.JobsExecutionAuditLog{}
jobsExecutionAuditLog := &postgres.JobsExecutionAuditLog{
JobExecutionStatus: "WAITING",
}
defer func() { go handler.auditor.JobsExecutionAndStatus(jobsExecutionAuditLog) }()

userEmail := req.Header.Get(utility.UserEmailHeaderKey)
Expand Down
21 changes: 21 additions & 0 deletions proctord/jobs/execution/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ func (suite *ExecutionHandlerTestSuite) TestJobStatusShouldReturn404IfJobStatusI
assert.Equal(suite.T(), http.StatusNotFound, response.StatusCode)
}

func (suite *ExecutionHandlerTestSuite) TestJobStatusShouldReturn200IfJobStatusIsWaiting() {
t := suite.T()

jobName := "sample-job-name"

url := fmt.Sprintf("%s/jobs/execute/%s/status", suite.TestServer.URL, jobName)

suite.mockStore.On("GetJobExecutionStatus", jobName).Return("WAITING", nil).Once()

req, _ := http.NewRequest("GET", url, nil)

response, _ := suite.Client.Do(req)
suite.mockStore.AssertExpectations(t)
assert.Equal(suite.T(), http.StatusOK, response.StatusCode)

buf := new(bytes.Buffer)
buf.ReadFrom(response.Body)
jobStatus := buf.String()
assert.Equal(suite.T(), utility.JobWaiting, jobStatus)
}

func (suite *ExecutionHandlerTestSuite) TestJobStatusShouldReturn500OnError() {
t := suite.T()

Expand Down

0 comments on commit ecb250c

Please sign in to comment.