Fix null value crash in postgresql_extensible input (#4689)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user