github.com/shuguocloud/go-zero@v1.3.0/core/iox/textfile_test.go (about)

     1  package iox
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestCountLines(t *testing.T) {
    12  	const val = `1
    13  2
    14  3
    15  4`
    16  	file, err := ioutil.TempFile(os.TempDir(), "test-")
    17  	if err != nil {
    18  		t.Fatal(err)
    19  	}
    20  	defer os.Remove(file.Name())
    21  
    22  	file.WriteString(val)
    23  	file.Close()
    24  	lines, err := CountLines(file.Name())
    25  	assert.Nil(t, err)
    26  	assert.Equal(t, 4, lines)
    27  }