diff --git a/api/router.go b/api/router.go index f7c95fd3..3536ab09 100644 --- a/api/router.go +++ b/api/router.go @@ -232,7 +232,6 @@ func Router(c *ctx.AptlyContext) http.Handler { api.GET("/tasks/:id/return_value", apiTasksReturnValueShow) api.GET("/tasks/:id", apiTasksShow) api.DELETE("/tasks/:id", apiTasksDelete) - api.POST("/tasks-dummy", apiTasksDummy) } return router diff --git a/api/task.go b/api/task.go index d9ea737b..1d136325 100644 --- a/api/task.go +++ b/api/task.go @@ -1,10 +1,8 @@ package api import ( - "net/http" "strconv" - "github.com/aptly-dev/aptly/aptly" "github.com/aptly-dev/aptly/task" "github.com/gin-gonic/gin" ) @@ -203,21 +201,3 @@ func apiTasksDelete(c *gin.Context) { 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 - }) -} diff --git a/api/task_test.go b/api/task_test.go deleted file mode 100644 index 59c981a0..00000000 --- a/api/task_test.go +++ /dev/null @@ -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, "[]") -}