File: list_test.go

package info (click to toggle)
aptly 1.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 49,928 kB
  • sloc: python: 10,398; sh: 252; makefile: 184
file content (54 lines) | stat: -rw-r--r-- 1,651 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package task

import (
	"errors"

	"github.com/aptly-dev/aptly/aptly"

	// need to import as check as otherwise List is redeclared
	check "gopkg.in/check.v1"
)

type ListSuite struct{}

var _ = check.Suite(&ListSuite{})

func (s *ListSuite) TestList(c *check.C) {
	list := NewList()
	c.Assert(len(list.GetTasks()), check.Equals, 0)

	task, err := list.RunTaskInBackground("Successful task", nil, func(out aptly.Progress, detail *Detail) (*ProcessReturnValue, error) {
		return nil, nil
	})
	c.Assert(err, check.IsNil)
	_, _ = list.WaitForTaskByID(task.ID)

	tasks := list.GetTasks()
	c.Assert(len(tasks), check.Equals, 1)
	task, _ = list.GetTaskByID(task.ID)
	c.Check(task.State, check.Equals, SUCCEEDED)
	output, _ := list.GetTaskOutputByID(task.ID)
	c.Check(output, check.Equals, "Task succeeded")
	detail, _ := list.GetTaskDetailByID(task.ID)
	c.Check(detail, check.Equals, struct{}{})

	task, err = list.RunTaskInBackground("Faulty task", nil, func(out aptly.Progress, detail *Detail) (*ProcessReturnValue, error) {
		detail.Store("Details")
		out.Printf("Test Progress\n")
		return nil, errors.New("Task failed")
	})
	c.Assert(err, check.IsNil)
	_, _ = list.WaitForTaskByID(task.ID)

	tasks = list.GetTasks()
	c.Assert(len(tasks), check.Equals, 2)
	task, _ = list.GetTaskByID(task.ID)
	c.Check(task.State, check.Equals, FAILED)
	output, _ = list.GetTaskOutputByID(task.ID)
	c.Check(output, check.Equals, "Test Progress\nTask failed with error: Task failed")
	detail, _ = list.GetTaskDetailByID(task.ID)
	c.Check(detail, check.Equals, "Details")
	_, deleteErr := list.DeleteTaskByID(task.ID)
	c.Check(deleteErr, check.IsNil)
        list.Stop()
}