github.com/openshift/installer@v1.4.17/pkg/lineprinter/lineprinter_test.go (about)

     1  package lineprinter
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  type printer struct {
    10  	data [][]interface{}
    11  }
    12  
    13  func (p *printer) print(args ...interface{}) {
    14  	p.data = append(p.data, args)
    15  }
    16  
    17  func TestLinePrinter(t *testing.T) {
    18  	print := &printer{}
    19  	lp := &LinePrinter{Print: print.print}
    20  	data := []byte("Hello\nWorld\nAnd more")
    21  	n, err := lp.Write(data)
    22  	if err != nil {
    23  		t.Fatal(err)
    24  	}
    25  
    26  	assert.Equal(t, len(data), n)
    27  	assert.Equal(
    28  		t,
    29  		[][]interface{}{
    30  			{"Hello\n"},
    31  			{"World\n"},
    32  		},
    33  		print.data,
    34  	)
    35  	print.data = [][]interface{}{}
    36  
    37  	err = lp.Close()
    38  	if err != nil {
    39  		t.Fatal(err)
    40  	}
    41  
    42  	assert.Equal(
    43  		t,
    44  		[][]interface{}{
    45  			{"And more"},
    46  		},
    47  		print.data,
    48  	)
    49  }