test(be): add test for schedule

This commit is contained in:
Denis Gukov 2021-09-06 19:26:35 +05:00
parent efc44277ee
commit 032f46f7b0
3 changed files with 70 additions and 1 deletions

View File

@ -16,6 +16,7 @@ var userPathTestUser *db.User
var userProject *db.Project
var userKey *db.AccessKey
var task *db.Task
var schedule *db.Schedule
// Runtime created simple ID values for some items we need to reference in other objects
var repoID int64
@ -26,12 +27,12 @@ var templateID int64
var capabilities = map[string][]string{
"user": {},
"project": {"user"},
//"access_key": {"project"},
"repository": {"access_key"},
"inventory": {"repository"},
"environment": {"repository"},
"template": {"repository", "inventory", "environment"},
"task": {"template"},
"schedule": {"template"},
}
func capabilityWrapper(cap string) func(t *trans.Transaction) {
@ -63,6 +64,8 @@ func resolveCapability(caps []string, resolved []string, uid string) {
//Add dep specific stuff
switch v {
case "schedule":
schedule = addSchedule()
case "user":
userPathTestUser = addUser()
case "project":
@ -122,6 +125,7 @@ var pathSubPatterns = []func() string{
func() string { return strconv.Itoa(int(environmentID)) },
func() string { return strconv.Itoa(int(templateID)) },
func() string { return strconv.Itoa(task.ID) },
func() string { return strconv.Itoa(schedule.ID) },
}
// alterRequestPath with the above slice of functions
@ -157,6 +161,9 @@ func alterRequestBody(t *trans.Transaction) {
if task != nil {
bodyFieldProcessor("task_id", task.ID, &request)
}
if schedule != nil {
bodyFieldProcessor("schedule_id", schedule.ID, &request)
}
// Inject object ID to body for PUT requests
if strings.ToLower(t.Request.Method) == "put" {

View File

@ -138,6 +138,21 @@ func addUser() *db.User {
return &user
}
func addSchedule() *db.Schedule {
schedule, err := store.CreateSchedule(db.Schedule{
TemplateID: int(templateID),
CronFormat: "* * * 1 *",
ProjectID: userProject.ID,
})
if err != nil {
fmt.Println(err)
}
return &schedule
}
func addTask() *db.Task {
t := db.Task{
TemplateID: int(templateID),

View File

@ -340,6 +340,31 @@ definitions:
override_args:
type: boolean
ScheduleRequest:
type: object
properties:
id:
type: integer
cron_format:
type: string
project_id:
type: integer
template_id:
type: integer
Schedule:
type: object
properties:
id:
type: integer
cron_format:
type: string
project_id:
type: integer
template_id:
type: integer
Event:
type: object
properties:
@ -1199,6 +1224,28 @@ paths:
204:
description: template removed
# project schedules
/project/{project_id}/schedules:
parameters:
- $ref: "#/parameters/project_id"
post:
tags:
- schedule
summary: create schedule
parameters:
- name: schedule
in: body
required: true
schema:
$ref: "#/definitions/ScheduleRequest"
responses:
201:
description: schedule created
schema:
$ref: "#/definitions/Schedule"
# tasks
/project/{project_id}/tasks:
parameters: