Fix null value crash in postgresql_extensible input (#4689)

This commit is contained in:
Greg
2018-09-18 10:08:13 -06:00
committed by Daniel Nelson
parent f05fdde48b
commit d3ad591481
2 changed files with 48 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
package postgresql_extensible
import (
"errors"
"fmt"
"testing"
@@ -223,3 +224,41 @@ func TestPostgresqlIgnoresUnwantedColumns(t *testing.T) {
assert.False(t, acc.HasMeasurement(col))
}
}
func TestAccRow(t *testing.T) {
p := Postgresql{}
var acc testutil.Accumulator
columns := []string{"datname", "cat"}
testRows := []fakeRow{
{fields: []interface{}{1, "gato"}},
{fields: []interface{}{nil, "gato"}},
{fields: []interface{}{"name", "gato"}},
}
for i := range testRows {
err := p.accRow("pgTEST", testRows[i], &acc, columns)
if err != nil {
t.Fatalf("Scan failed: %s", err)
}
}
}
type fakeRow struct {
fields []interface{}
}
func (f fakeRow) Scan(dest ...interface{}) error {
if len(f.fields) != len(dest) {
return errors.New("Nada matchy buddy")
}
for i, d := range dest {
switch d.(type) {
case (*interface{}):
*d.(*interface{}) = f.fields[i]
default:
return fmt.Errorf("Bad type %T", d)
}
}
return nil
}