add separator checking and return error
This commit is contained in:
@@ -15,6 +15,7 @@ func Test_CSV_ParseFile(t *testing.T) {
|
||||
filePath string
|
||||
expectedInserted int
|
||||
expectedRejected int
|
||||
expectError bool
|
||||
validateInserted func(t *testing.T, inserted []meteo.MeteoData)
|
||||
validateRejected func(t *testing.T, rejected []meteo.RejectedMeteoData)
|
||||
}{
|
||||
@@ -109,6 +110,7 @@ func Test_CSV_ParseFile(t *testing.T) {
|
||||
filePath: "./../../../assets/test_7.csv",
|
||||
expectedInserted: 0,
|
||||
expectedRejected: 1,
|
||||
expectError: false,
|
||||
validateInserted: func(t *testing.T, inserted []meteo.MeteoData) {
|
||||
assert.Empty(t, inserted)
|
||||
},
|
||||
@@ -118,6 +120,15 @@ func Test_CSV_ParseFile(t *testing.T) {
|
||||
assert.Equal(t, ";Madrid;11,55;6,25;0;10", rejected[0].RowValue)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid separator comma instead of semicolon",
|
||||
filePath: "./../../../assets/test_8.csv",
|
||||
expectedInserted: 0,
|
||||
expectedRejected: 0,
|
||||
expectError: true,
|
||||
validateInserted: nil,
|
||||
validateRejected: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -127,12 +138,15 @@ func Test_CSV_ParseFile(t *testing.T) {
|
||||
defer file.Close()
|
||||
|
||||
csvIngest := &meteo.CSV{}
|
||||
fileStats := &meteo.FileStats{}
|
||||
inserted, rejected, err := csvIngest.Parse(file)
|
||||
|
||||
if tt.expectError {
|
||||
assert.Error(t, err)
|
||||
assert.ErrorIs(t, err, meteo.ErrCannotParseFile)
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.expectedInserted, fileStats.RowsInserted)
|
||||
assert.Equal(t, tt.expectedRejected, fileStats.RowsRejected)
|
||||
|
||||
if tt.validateInserted != nil {
|
||||
tt.validateInserted(t, inserted)
|
||||
|
||||
Reference in New Issue
Block a user