File: once_writer_test.go

package info (click to toggle)
golang-github-jesseduffield-lazycore 0.0~git20221023.718a4ca-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 136 kB
  • sloc: makefile: 2
file content (19 lines) | stat: -rw-r--r-- 368 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
package utils

import (
	"bytes"
	"testing"
)

func TestOnceWriter(t *testing.T) {
	innerWriter := bytes.NewBuffer(nil)
	counter := 0
	onceWriter := NewOnceWriter(innerWriter, func() {
		counter += 1
	})
	_, _ = onceWriter.Write([]byte("hello"))
	_, _ = onceWriter.Write([]byte("hello"))
	if counter != 1 {
		t.Errorf("expected counter to be 1, got %d", counter)
	}
}