func createTestTask(taskGuid string) *models.Task { task := model_helpers.NewValidTask(taskGuid) task.Domain = "test-domain" task.TaskDefinition.RootFs = "some:rootfs" task.TaskDefinition.Action = models.WrapAction(&models.RunAction{User: "******", Path: "/bin/true"}) return task }
statusCodes = make(chan int) reqCount = make(chan struct{}, task_handler.POOL_SIZE) fakeServer.RouteToHandler("POST", "/the-callback/url", func(w http.ResponseWriter, req *http.Request) { reqCount <- struct{}{} w.WriteHeader(<-statusCodes) }) callbackURL = fakeServer.URL() + "/the-callback/url" }) AfterEach(func() { close(statusCodes) }) simulateTaskCompleting := func() { task := model_helpers.NewValidTask("the-task-guid") task.CompletionCallbackUrl = callbackURL enqueue <- task } Context("when the task has a completion callback URL", func() { It("marks the task as resolving", func() { Expect(fakeBBS.ResolvingTaskCallCount()).To(Equal(0)) simulateTaskCompleting() statusCodes <- 200 Eventually(fakeBBS.ResolveTaskCallCount).Should(Equal(1)) actualGuid := fakeBBS.ResolveTaskArgsForCall(0) Expect(actualGuid).To(Equal("the-task-guid")) })
validCreateRequest = receptor.TaskCreateRequest{ TaskGuid: "task-guid-1", Domain: "test-domain", RootFS: "docker://docker", Action: models.WrapAction(&models.RunAction{User: "******", Path: "/bin/bash", Args: []string{"echo", "hi"}}), MemoryMB: 24, DiskMB: 12, CPUWeight: 10, LogGuid: "guid", LogSource: "source-name", ResultFile: "result-file", Annotation: "some annotation", Privileged: true, } expectedTask = model_helpers.NewValidTask("task-guid-1") expectedTask.Domain = "test-domain" expectedTask.TaskDefinition.RootFs = "docker://docker" expectedTask.TaskDefinition.Action = models.WrapAction(&models.RunAction{User: "******", Path: "/bin/bash", Args: []string{"echo", "hi"}}) expectedTask.TaskDefinition.MemoryMb = 24 expectedTask.TaskDefinition.DiskMb = 12 expectedTask.TaskDefinition.CpuWeight = 10 expectedTask.TaskDefinition.LogGuid = "guid" expectedTask.TaskDefinition.LogSource = "source-name" expectedTask.TaskDefinition.ResultFile = "result-file" expectedTask.TaskDefinition.Annotation = "some annotation" expectedTask.TaskDefinition.Privileged = true expectedTask.TaskDefinition.EgressRules = nil expectedTask.TaskDefinition.MetricsGuid = "" expectedTask.TaskDefinition.EnvironmentVariables = nil
import ( "github.com/cloudfoundry-incubator/bbs/models" "github.com/cloudfoundry-incubator/bbs/models/internal/model_helpers" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("TaskDB", func() { Describe("Tasks", func() { Context("when there are tasks", func() { var expectedTasks []*models.Task BeforeEach(func() { expectedTasks = []*models.Task{ model_helpers.NewValidTask("a-guid"), model_helpers.NewValidTask("b-guid"), } for _, t := range expectedTasks { etcdHelper.SetRawTask(t) } }) It("returns all the tasks", func() { tasks, err := etcdDB.Tasks(logger, nil) Expect(err).NotTo(HaveOccurred()) Expect(tasks.GetTasks()).To(ConsistOf(expectedTasks)) }) It("can filter", func() { tasks, err := etcdDB.Tasks(logger, func(t *models.Task) bool { return t.TaskGuid == "b-guid" })
server.Close() }) JustBeforeEach(func() { var err error response, err = http.Post(server.URL, "application/json", bytes.NewBuffer(payload)) Expect(err).NotTo(HaveOccurred()) }) Describe("when the handler receives a task", func() { var task *models.Task BeforeEach(func() { var err error task = model_helpers.NewValidTask("guid") payload, err = json.Marshal([]*models.Task{task}) Expect(err).NotTo(HaveOccurred()) }) It("enqueues the task on the worker", func() { Expect(enqueue).To(Receive(Equal(task))) }) It("returns 202", func() { Expect(response.StatusCode).To(Equal(http.StatusAccepted)) }) }) Describe("when the handler receives a bogus payload", func() { BeforeEach(func() {
) var _ = Describe("Task API", func() { var ( actualTasks []*models.Task expectedTasks []*models.Task filter db.TaskFilter getErr error ) BeforeEach(func() { filter = nil actualTasks = nil expectedTasks = []*models.Task{model_helpers.NewValidTask("a-guid"), model_helpers.NewValidTask("b-guid")} expectedTasks[1].Domain = "b-domain" expectedTasks[1].CellId = "b-cell" for _, t := range expectedTasks { etcdHelper.SetRawTask(t) } }) Describe("GET /v1/tasks", func() { Context("all tasks", func() { BeforeEach(func() { actualTasks, getErr = client.Tasks() }) It("responds without error", func() { Expect(getErr).NotTo(HaveOccurred())