fix datastore Put and added tests (#402)

This commit is contained in:
Pedro Nasser
2016-12-07 14:59:54 -02:00
committed by Travis Reeder
parent 0baf03841f
commit 9382f0b133
6 changed files with 132 additions and 37 deletions

View File

@@ -524,6 +524,10 @@ func buildFilterRouteQuery(filter *models.RouteFilter) string {
}
func (ds *PostgresDatastore) Put(ctx context.Context, key, value []byte) error {
if key == nil || len(key) == 0 {
return models.ErrDatastoreEmptyKey
}
_, err := ds.db.Exec(`
INSERT INTO extras (
key,
@@ -531,7 +535,7 @@ func (ds *PostgresDatastore) Put(ctx context.Context, key, value []byte) error {
)
VALUES ($1, $2)
ON CONFLICT (key) DO UPDATE SET
value = $1;
value = $2;
`, string(key), string(value))
if err != nil {
@@ -542,6 +546,10 @@ func (ds *PostgresDatastore) Put(ctx context.Context, key, value []byte) error {
}
func (ds *PostgresDatastore) Get(ctx context.Context, key []byte) ([]byte, error) {
if key == nil || len(key) == 0 {
return nil, models.ErrDatastoreEmptyKey
}
row := ds.db.QueryRow("SELECT value FROM extras WHERE key=$1", key)
var value string