mssqlbulkloader/readercsv_test.go
2023-04-03 19:12:30 +05:00

43 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"io"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCsvReaderBasic(t *testing.T) {
f, err := os.Open("testdata/csv/9729337841_20032023_084313667.csv")
assert.NoError(t, err)
options := &Options{
encoding: "win1251",
comma: rune(";"[0]),
skipRows: 3,
fieldsTypes: "s ttffsssss",
dateFormat: "02.01.2006",
timestampFormat: "02.01.2006 15:04:05",
timezone: time.Local}
csvReader, err := NewCsvReader(f, options)
assert.NoError(t, err)
assert.Equal(t, []string{"RRN", "Дата операции", "Дата ПП", "Сумма операции", "Сумма расчета", "Номер карты", "Код авторизации", "Тип операции", "Доп. информация_1", "Доп. информация_2"}, csvReader.GetHeader())
row, err := csvReader.GetRow(false)
assert.NoError(t, err)
t1 := time.Date(2023, 03, 19, 17, 49, 35, 0, time.Local)
t2 := time.Date(2023, 03, 20, 0, 0, 0, 0, time.Local)
assert.Equal(t, []any{"307814009186", t1, t2, 499.00, 488.52, "522598******7141", "REZE64", "Покупка", "35068281112", "307817403283"}, row)
row, err = csvReader.GetRow(false)
assert.Equal(t, err, io.EOF)
err = csvReader.Close()
assert.NoError(t, err)
}