mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-09 08:42:49 +01:00
Add test for jobs (#34)
This commit is contained in:
@@ -39,7 +39,7 @@ type Service interface {
|
||||
CurrentUserData(context.Context) (*model.UserDataResponse, error)
|
||||
UpdateCurrentUserData(context.Context, *model.UserData) (*model.UserDataResponse, error)
|
||||
ListJobs(context.Context) ([]*model.JobResponse, error)
|
||||
RunJob(context.Context, *model.JobForm) error
|
||||
RunJob(context.Context, *model.JobForm) (*model.JobResponse, error)
|
||||
GetJob(context.Context, string) (*model.JobResponse, error)
|
||||
UpdateJob(context.Context, string, *model.JobUpdate) (*model.JobResponse, error)
|
||||
GetLogs(context.Context, string) ([]*model.LogEntry, error)
|
||||
@@ -346,7 +346,8 @@ func (s *server) runJobHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
response(w, nil, s.service.RunJob(r.Context(), jobP))
|
||||
result, err := s.service.RunJob(r.Context(), jobP)
|
||||
response(w, result, err)
|
||||
}
|
||||
|
||||
func (s *server) getJobHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -95,34 +95,34 @@ var Tests = []struct {
|
||||
Args: Args{Method: "Get", URL: "/jobs"},
|
||||
Want: Want{
|
||||
Status: 200,
|
||||
Body: []interface{}{map[string]interface{}{"automation": "hash.sha1", "id": "99cd67131b48", "payload": "test", "status": "created"}},
|
||||
Body: []interface{}{map[string]interface{}{"automation": "hash.sha1", "id": "b81c2366-ea37-43d2-b61b-03afdc21d985", "payload": "test", "status": "created"}},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
Name: "RunJob",
|
||||
Args: Args{Method: "Post", URL: "/jobs", Data: map[string]interface{}{"automation": "hash.sha1", "message": map[string]interface{}{"payload": "test"}}},
|
||||
Args: Args{Method: "Post", URL: "/jobs", Data: map[string]interface{}{"automation": "hash.sha1", "payload": "test"}},
|
||||
Want: Want{
|
||||
Status: 204,
|
||||
Body: nil,
|
||||
Status: 200,
|
||||
Body: map[string]interface{}{"automation": "hash.sha1", "id": "87390749-2125-4a87-91c5-da7e3f9bebf1", "payload": "test", "status": "created"},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
Name: "GetJob",
|
||||
Args: Args{Method: "Get", URL: "/jobs/99cd67131b48"},
|
||||
Args: Args{Method: "Get", URL: "/jobs/b81c2366-ea37-43d2-b61b-03afdc21d985"},
|
||||
Want: Want{
|
||||
Status: 200,
|
||||
Body: map[string]interface{}{"automation": "hash.sha1", "id": "99cd67131b48", "payload": "test", "status": "created"},
|
||||
Body: map[string]interface{}{"automation": "hash.sha1", "id": "b81c2366-ea37-43d2-b61b-03afdc21d985", "payload": "test", "status": "created"},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
Name: "UpdateJob",
|
||||
Args: Args{Method: "Put", URL: "/jobs/99cd67131b48", Data: map[string]interface{}{"running": false, "status": "failed"}},
|
||||
Args: Args{Method: "Put", URL: "/jobs/b81c2366-ea37-43d2-b61b-03afdc21d985", Data: map[string]interface{}{"running": false, "status": "failed"}},
|
||||
Want: Want{
|
||||
Status: 200,
|
||||
Body: map[string]interface{}{"automation": "hash.sha1", "id": "99cd67131b48", "payload": "test", "status": "failed"},
|
||||
Body: map[string]interface{}{"automation": "hash.sha1", "id": "b81c2366-ea37-43d2-b61b-03afdc21d985", "payload": "test", "status": "failed"},
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user