github.com/goreleaser/goreleaser@v1.25.1/internal/gio/safe_test.go (about) 1 package gio 2 3 import ( 4 "bytes" 5 "io" 6 "sync" 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestSafe(t *testing.T) { 14 chars := 30 15 16 var b bytes.Buffer 17 w := Safe(&b) 18 19 var wg sync.WaitGroup 20 wg.Add(chars) 21 for i := 0; i < chars; i++ { 22 go func() { 23 s, err := io.WriteString(w, "a") 24 assert.Equal(t, 1, s) 25 assert.NoError(t, err) 26 wg.Done() 27 }() 28 } 29 wg.Wait() 30 31 require.Len(t, b.String(), chars) 32 }