MCPcopy
hub / github.com/lxc/incus / TestHandleWriter

Function TestHandleWriter

internal/server/apparmor/qemuimg_test.go:9–44  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestHandleWriter(t *testing.T) {
10 status := []int64{}
11 var buffer bytes.Buffer
12 out := &nullWriteCloser{handleWriter(&buffer, func(percent int64, _ int64) {
13 status = append(status, percent)
14 })}
15
16 for i := range 101 {
17 for j := range 100 {
18 n, err := fmt.Fprintf(out, "\t (%02d.%02d/100%s)\r", i, j, "%")
19 if err != nil {
20 t.Fatal(err, n)
21 }
22
23 if i == 100 {
24 break
25 }
26 }
27 }
28
29 if len(status) != 100 {
30 t.Fatal(status)
31 }
32
33 for i := int64(1); i < 101; i++ {
34 if status[i-1] != i {
35 t.Fatal(status[i], i)
36 }
37 }
38
39 output := buffer.String()
40 // Do not check output carefully
41 if len(output) == 0 {
42 t.Fatal(output)
43 }
44}

Callers

nothing calls this directly

Calls 3

handleWriterFunction · 0.85
FatalMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…