Add test for jobs (#34)

This commit is contained in:
Jonas Plum
2022-02-27 18:33:50 +01:00
committed by GitHub
parent fd18458f3d
commit ffba7b4f5f
18 changed files with 181 additions and 80 deletions

View File

@@ -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) {

View File

@@ -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"},
},
},

View File

@@ -556,7 +556,7 @@
"test" : {
"example" : [ {
"automation" : "hash.sha1",
"id" : "99cd67131b48",
"id" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"payload" : "test",
"status" : "created"
} ]
@@ -585,8 +585,22 @@
"required" : true
},
"responses" : {
"204" : {
"content" : { },
"200" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/JobResponse"
}
},
"test" : {
"example" : {
"automation" : "hash.sha1",
"id" : "87390749-2125-4a87-91c5-da7e3f9bebf1",
"payload" : "test",
"status" : "created"
}
}
},
"description" : "successful operation"
}
},
@@ -603,7 +617,7 @@
"operationId" : "getJob",
"parameters" : [ {
"description" : "Job ID",
"example" : "99cd67131b48",
"example" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"in" : "path",
"name" : "id",
"required" : true,
@@ -622,7 +636,7 @@
"test" : {
"example" : {
"automation" : "hash.sha1",
"id" : "99cd67131b48",
"id" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"payload" : "test",
"status" : "created"
}
@@ -641,7 +655,7 @@
"operationId" : "updateJob",
"parameters" : [ {
"description" : "Job ID",
"example" : "99cd67131b48",
"example" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"in" : "path",
"name" : "id",
"required" : true,
@@ -671,7 +685,7 @@
"test" : {
"example" : {
"automation" : "hash.sha1",
"id" : "99cd67131b48",
"id" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"payload" : "test",
"status" : "failed"
}

View File

@@ -1791,7 +1791,7 @@ paths:
examples:
test:
- automation: hash.sha1
id: 99cd67131b48
id: b81c2366-ea37-43d2-b61b-03afdc21d985
payload: test
status: created
schema:
@@ -1815,11 +1815,18 @@ paths:
$ref: '#/definitions/JobForm'
x-example:
automation: hash.sha1
message:
payload: test
payload: test
responses:
"204":
"200":
description: successful operation
examples:
test:
automation: hash.sha1
id: 87390749-2125-4a87-91c5-da7e3f9bebf1
payload: test
status: created
schema:
$ref: '#/definitions/JobResponse'
security:
- roles:
- job:write
@@ -1835,14 +1842,14 @@ paths:
name: id
required: true
type: string
x-example: 99cd67131b48
x-example: b81c2366-ea37-43d2-b61b-03afdc21d985
responses:
"200":
description: successful operation
examples:
test:
automation: hash.sha1
id: 99cd67131b48
id: b81c2366-ea37-43d2-b61b-03afdc21d985
payload: test
status: created
schema:
@@ -1861,7 +1868,7 @@ paths:
name: id
required: true
type: string
x-example: 99cd67131b48
x-example: b81c2366-ea37-43d2-b61b-03afdc21d985
- description: Job object that needs to be added
in: body
name: job
@@ -1877,7 +1884,7 @@ paths:
examples:
test:
automation: hash.sha1
id: 99cd67131b48
id: b81c2366-ea37-43d2-b61b-03afdc21d985
payload: test
status: failed
schema:

View File

@@ -324,7 +324,7 @@
"test" : {
"example" : [ {
"automation" : "hash.sha1",
"id" : "99cd67131b48",
"id" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"payload" : "test",
"status" : "created"
} ]
@@ -353,8 +353,22 @@
"required" : true
},
"responses" : {
"204" : {
"content" : { },
"200" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/JobResponse"
}
},
"test" : {
"example" : {
"automation" : "hash.sha1",
"id" : "87390749-2125-4a87-91c5-da7e3f9bebf1",
"payload" : "test",
"status" : "created"
}
}
},
"description" : "successful operation"
}
},
@@ -371,7 +385,7 @@
"operationId" : "getJob",
"parameters" : [ {
"description" : "Job ID",
"example" : "99cd67131b48",
"example" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"in" : "path",
"name" : "id",
"required" : true,
@@ -390,7 +404,7 @@
"test" : {
"example" : {
"automation" : "hash.sha1",
"id" : "99cd67131b48",
"id" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"payload" : "test",
"status" : "created"
}
@@ -409,7 +423,7 @@
"operationId" : "updateJob",
"parameters" : [ {
"description" : "Job ID",
"example" : "99cd67131b48",
"example" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"in" : "path",
"name" : "id",
"required" : true,
@@ -439,7 +453,7 @@
"test" : {
"example" : {
"automation" : "hash.sha1",
"id" : "99cd67131b48",
"id" : "b81c2366-ea37-43d2-b61b-03afdc21d985",
"payload" : "test",
"status" : "failed"
}

View File

@@ -1520,7 +1520,7 @@ paths:
examples:
test:
- automation: hash.sha1
id: 99cd67131b48
id: b81c2366-ea37-43d2-b61b-03afdc21d985
payload: test
status: created
schema:
@@ -1544,11 +1544,18 @@ paths:
$ref: '#/definitions/JobForm'
x-example:
automation: hash.sha1
message:
payload: test
payload: test
responses:
"204":
"200":
description: successful operation
examples:
test:
automation: hash.sha1
id: 87390749-2125-4a87-91c5-da7e3f9bebf1
payload: test
status: created
schema:
$ref: '#/definitions/JobResponse'
security:
- roles:
- job:write
@@ -1564,14 +1571,14 @@ paths:
name: id
required: true
type: string
x-example: 99cd67131b48
x-example: b81c2366-ea37-43d2-b61b-03afdc21d985
responses:
"200":
description: successful operation
examples:
test:
automation: hash.sha1
id: 99cd67131b48
id: b81c2366-ea37-43d2-b61b-03afdc21d985
payload: test
status: created
schema:
@@ -1590,7 +1597,7 @@ paths:
name: id
required: true
type: string
x-example: 99cd67131b48
x-example: b81c2366-ea37-43d2-b61b-03afdc21d985
- description: Job object that needs to be added
in: body
name: job
@@ -1606,7 +1613,7 @@ paths:
examples:
test:
automation: hash.sha1
id: 99cd67131b48
id: b81c2366-ea37-43d2-b61b-03afdc21d985
payload: test
status: failed
schema: