textfile_test.go 397 B

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