debian-forge-cli/pkg/progress/syncwriter_test.go
Simon de Vlieger f4bbd3e048 import: move bib files to correct path
Moves the files imported from `bootc-image-builder` directly under `pkg`
so they can be imported in reverse. Also fix up any import paths at the
same time.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-31 19:42:59 +00:00

44 lines
804 B
Go

package progress_test
import (
"bufio"
"bytes"
"fmt"
"strings"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/osbuild/image-builder-cli/pkg/progress"
)
func TestSyncWriter(t *testing.T) {
var mu sync.Mutex
var buf bytes.Buffer
var wg sync.WaitGroup
for id := 0; id < 100; id++ {
wg.Add(1)
w := progress.NewSyncedWriter(&mu, &buf)
go func(id int) {
defer wg.Done()
for i := 0; i < 500; i++ {
fmt.Fprintln(w, strings.Repeat(fmt.Sprintf("%v", id%10), 60))
time.Sleep(10 * time.Nanosecond)
}
}(id)
}
wg.Wait()
scanner := bufio.NewScanner(&buf)
for {
if !scanner.Scan() {
break
}
line := scanner.Text()
assert.True(t, len(line) == 60, fmt.Sprintf("len %v: line: %v", len(line), line))
}
assert.NoError(t, scanner.Err())
}