File: waiting_task_test.go

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (62 lines) | stat: -rw-r--r-- 1,212 bytes parent folder | download | duplicates (4)
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
55
56
57
58
59
60
61
62
package tasklog

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestWaitingTaskDisplaysWaitingStatus(t *testing.T) {
	task := NewWaitingTask("example")

	assert.Equal(t, "example: ...", (<-task.Updates()).S)
}

func TestWaitingTaskCallsDoneWhenComplete(t *testing.T) {
	task := NewWaitingTask("example")

	select {
	case v, ok := <-task.Updates():
		if ok {
			assert.Equal(t, "example: ...", v.S)
		} else {
			t.Fatal("expected channel to be open")
		}
	default:
	}

	task.Complete()

	if _, ok := <-task.Updates(); ok {
		t.Fatalf("expected channel to be closed")
	}
}

func TestWaitingTaskPanicsWithMultipleDoneCalls(t *testing.T) {
	task := NewWaitingTask("example")

	task.Complete()

	defer func() {
		if err := recover(); err == nil {
			t.Fatal("tasklog: expected panic()")
		} else {
			if s, ok := err.(error); ok {
				assert.Equal(t, "close of closed channel", s.Error())
			} else {
				t.Fatal("tasklog: expected panic() to implement error")
			}
		}
	}()

	task.Complete()
}

func TestWaitingTaskIsThrottled(t *testing.T) {
	task := NewWaitingTask("example")

	throttled := task.Throttled()

	assert.True(t, throttled,
		"tasklog: expected *WaitingTask to be Throttle()-d")
}