File: simple_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 (76 lines) | stat: -rw-r--r-- 1,397 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package tasklog

import (
	"testing"

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

func TestSimpleTaskLogLogsUpdates(t *testing.T) {
	task := NewSimpleTask()

	var updates []*Update

	go func() {
		for update := range task.Updates() {
			updates = append(updates, update)
		}
		task.OnComplete()
	}()

	task.Log("Hello, world")
	task.Complete()

	require.Len(t, updates, 1)
	assert.Equal(t, "Hello, world", updates[0].S)
}

func TestSimpleTaskLogfLogsFormattedUpdates(t *testing.T) {
	task := NewSimpleTask()

	var updates []*Update

	go func() {
		for update := range task.Updates() {
			updates = append(updates, update)
		}
		task.OnComplete()
	}()

	task.Logf("Hello, world (%d)", 3+4)
	task.Complete()

	require.Len(t, updates, 1)
	assert.Equal(t, "Hello, world (7)", updates[0].S)
}

func TestSimpleTaskCompleteClosesUpdates(t *testing.T) {
	task := NewSimpleTask()

	select {
	case <-task.Updates():
		t.Fatalf("tasklog: unexpected update from *SimpleTask")
	default:
	}

	go func() {
		<-task.Updates()
		task.OnComplete()
	}()

	task.Complete()

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

func TestSimpleTaskIsNotThrottled(t *testing.T) {
	task := NewSimpleTask()

	throttled := task.Throttled()

	assert.False(t, throttled,
		"tasklog: expected *SimpleTask not to be Throttle()-d")
}