mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-12 06:30:35 +00:00
task-dummy: remove internal testing API
This commit is contained in:
@@ -232,7 +232,6 @@ func Router(c *ctx.AptlyContext) http.Handler {
|
|||||||
api.GET("/tasks/:id/return_value", apiTasksReturnValueShow)
|
api.GET("/tasks/:id/return_value", apiTasksReturnValueShow)
|
||||||
api.GET("/tasks/:id", apiTasksShow)
|
api.GET("/tasks/:id", apiTasksShow)
|
||||||
api.DELETE("/tasks/:id", apiTasksDelete)
|
api.DELETE("/tasks/:id", apiTasksDelete)
|
||||||
api.POST("/tasks-dummy", apiTasksDummy)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
|||||||
-20
@@ -1,10 +1,8 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/aptly-dev/aptly/aptly"
|
|
||||||
"github.com/aptly-dev/aptly/task"
|
"github.com/aptly-dev/aptly/task"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@@ -203,21 +201,3 @@ func apiTasksDelete(c *gin.Context) {
|
|||||||
|
|
||||||
c.JSON(200, delTask)
|
c.JSON(200, delTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Dummy endpoint used for testing.
|
|
||||||
// @Description **Dummy endpoint used for testing**
|
|
||||||
// @Tags Tasks
|
|
||||||
// @Produce json
|
|
||||||
// @Param _async query bool false "Run task in background using tasks API"
|
|
||||||
// @Success 200 {object} task.ProcessReturnValue
|
|
||||||
// @Router /api/tasks-dummy [post]
|
|
||||||
func apiTasksDummy(c *gin.Context) {
|
|
||||||
resources := []string{"dummy"}
|
|
||||||
taskName := "Dummy task"
|
|
||||||
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
|
||||||
out.Printf("Dummy task started\n")
|
|
||||||
detail.Store([]int{1, 2, 3})
|
|
||||||
out.Printf("Dummy task finished\n")
|
|
||||||
return &task.ProcessReturnValue{Code: http.StatusTeapot, Value: []int{1, 2, 3}}, nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/aptly-dev/aptly/task"
|
|
||||||
|
|
||||||
. "gopkg.in/check.v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TaskSuite struct {
|
|
||||||
ApiSuite
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = Suite(&TaskSuite{})
|
|
||||||
|
|
||||||
func (s *TaskSuite) TestTasksDummy(c *C) {
|
|
||||||
response, _ := s.HTTPRequest("POST", "/api/tasks-dummy", nil)
|
|
||||||
c.Check(response.Code, Equals, 418)
|
|
||||||
c.Check(response.Body.String(), Equals, "[1,2,3]")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *TaskSuite) TestTasksDummyAsync(c *C) {
|
|
||||||
response, _ := s.HTTPRequest("POST", "/api/tasks-dummy?_async=true", nil)
|
|
||||||
c.Check(response.Code, Equals, 202)
|
|
||||||
var t task.Task
|
|
||||||
err := json.Unmarshal(response.Body.Bytes(), &t)
|
|
||||||
c.Assert(err, IsNil)
|
|
||||||
c.Check(t.Name, Equals, "Dummy task")
|
|
||||||
response, _ = s.HTTPRequest("GET", fmt.Sprintf("/api/tasks/%d/wait", t.ID), nil)
|
|
||||||
err = json.Unmarshal(response.Body.Bytes(), &t)
|
|
||||||
c.Assert(err, IsNil)
|
|
||||||
c.Check(t.State, Equals, task.SUCCEEDED)
|
|
||||||
response, _ = s.HTTPRequest("GET", fmt.Sprintf("/api/tasks/%d/detail", t.ID), nil)
|
|
||||||
c.Check(response.Code, Equals, 200)
|
|
||||||
c.Check(response.Body.String(), Equals, "[1,2,3]")
|
|
||||||
response, _ = s.HTTPRequest("GET", fmt.Sprintf("/api/tasks/%d/output", t.ID), nil)
|
|
||||||
c.Check(response.Code, Equals, 200)
|
|
||||||
c.Check(response.Body.String(), Matches, "\"Dummy task started.*")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *TaskSuite) TestTaskDelete(c *C) {
|
|
||||||
response, _ := s.HTTPRequest("POST", "/api/tasks-dummy?_async=true", nil)
|
|
||||||
c.Check(response.Code, Equals, 202)
|
|
||||||
c.Check(response.Body.String(), Equals, "{\"Name\":\"Dummy task\",\"ID\":1,\"State\":0}")
|
|
||||||
// Give the task time to start
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
response, _ = s.HTTPRequest("DELETE", "/api/tasks/1", nil)
|
|
||||||
c.Check(response.Code, Equals, 200)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *TaskSuite) TestTasksClear(c *C) {
|
|
||||||
response, _ := s.HTTPRequest("POST", "/api/tasks-dummy?_async=true", nil)
|
|
||||||
c.Check(response.Code, Equals, 202)
|
|
||||||
var t task.Task
|
|
||||||
err := json.Unmarshal(response.Body.Bytes(), &t)
|
|
||||||
c.Assert(err, IsNil)
|
|
||||||
c.Check(t.Name, Equals, "Dummy task")
|
|
||||||
response, _ = s.HTTPRequest("GET", "/api/tasks-wait", nil)
|
|
||||||
c.Check(response.Code, Equals, 200)
|
|
||||||
response, _ = s.HTTPRequest("GET", "/api/tasks", nil)
|
|
||||||
c.Check(response.Code, Equals, 200)
|
|
||||||
var ts []task.Task
|
|
||||||
err = json.Unmarshal(response.Body.Bytes(), &ts)
|
|
||||||
c.Assert(err, IsNil)
|
|
||||||
c.Check(len(ts), Equals, 1)
|
|
||||||
c.Check(ts[0].State, Equals, task.SUCCEEDED)
|
|
||||||
response, _ = s.HTTPRequest("POST", "/api/tasks-clear", nil)
|
|
||||||
c.Check(response.Code, Equals, 200)
|
|
||||||
response, _ = s.HTTPRequest("GET", "/api/tasks", nil)
|
|
||||||
c.Check(response.Code, Equals, 200)
|
|
||||||
c.Check(response.Body.String(), Equals, "[]")
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user