feat: add skipRowOnError handling for raw line protocol files (#419)

* feat: add skipRowOnError for raw line protocol files

* use common code from influxdb instead of copying

* add test

* remove dead code comment
This commit is contained in:
Andrew Lee
2022-07-01 10:14:14 -06:00
committed by GitHub
parent e5707cd63c
commit da2899d71d
5 changed files with 125 additions and 6 deletions

View File

@ -0,0 +1,68 @@
package csv2lp
import (
"io"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestLineProtocolFilter(t *testing.T) {
var tests = []struct {
input string
expected string
}{
{
strings.Join([]string{
"weather,location=us-midwest temperature=42 1465839830100400200",
"awefw.,weather,location=us-east temperature=36 1465839830100400203",
"weather,location=us-blah temperature=32 1465839830100400204",
"weather,location=us-central temperature=31 1465839830100400205",
}, "\n"),
strings.Join([]string{
"weather,location=us-midwest temperature=42 1465839830100400200",
"weather,location=us-blah temperature=32 1465839830100400204",
"weather,location=us-central temperature=31 1465839830100400205",
}, "\n"),
},
{
strings.Join([]string{
"weather,location=us-midwest temperature=42 1465839830100400200",
"weather,location=us-east temperature=36 1465839830100400203",
"weather,location=us-blah temperature=32=33 1465839830100400204",
"weather,,location=us-blah temperature=32 1465839830100400204",
"weather,location=us-central temperature=31 1465839830100400205",
}, "\n"),
strings.Join([]string{
"weather,location=us-midwest temperature=42 1465839830100400200",
"weather,location=us-east temperature=36 1465839830100400203",
"weather,location=us-central temperature=31 1465839830100400205",
}, "\n"),
},
{
strings.Join([]string{
"weather,location=us-midwest temperature=42 1465839830100400200",
"awefw.,weather,location=us-east temperature=36 1465839830100400203",
" weather,location=us-blah temperature=32 1465839830100400204",
"weather,location=us-east temperature=36 1465839830100400203 13413413",
"weather,location=us-central temperature=31 1465839830100400205",
"# this is a comment",
}, "\n"),
strings.Join([]string{
"weather,location=us-midwest temperature=42 1465839830100400200",
" weather,location=us-blah temperature=32 1465839830100400204",
"weather,location=us-central temperature=31 1465839830100400205",
}, "\n"),
},
}
for _, tt := range tests {
reader := LineProtocolFilter(strings.NewReader(tt.input))
b, err := io.ReadAll(reader)
if err != nil {
t.Errorf("failed reading: %v", err)
continue
}
require.Equal(t, strings.TrimSpace(string(b)), strings.TrimSpace(tt.expected))
}
}