github.com/nektos/act@v0.2.63/pkg/common/line_writer_test.go (about)

     1  package common
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestLineWriter(t *testing.T) {
    10  	lines := make([]string, 0)
    11  	lineHandler := func(s string) bool {
    12  		lines = append(lines, s)
    13  		return true
    14  	}
    15  
    16  	lineWriter := NewLineWriter(lineHandler)
    17  
    18  	assert := assert.New(t)
    19  	write := func(s string) {
    20  		n, err := lineWriter.Write([]byte(s))
    21  		assert.NoError(err)
    22  		assert.Equal(len(s), n, s)
    23  	}
    24  
    25  	write("hello")
    26  	write(" ")
    27  	write("world!!\nextra")
    28  	write(" line\n and another\nlast")
    29  	write(" line\n")
    30  	write("no newline here...")
    31  
    32  	assert.Len(lines, 4)
    33  	assert.Equal("hello world!!\n", lines[0])
    34  	assert.Equal("extra line\n", lines[1])
    35  	assert.Equal(" and another\n", lines[2])
    36  	assert.Equal("last line\n", lines[3])
    37  }