Commit 3903abd0 authored by Diana Atanasova's avatar Diana Atanasova Committed by Trevor Conn

Return empty slice when searching for list of objects (Redis)

Fix #1392

When using Redis DB do not raise error when searching for
multiple objects and none object is found. Just return empty slice.
Signed-off-by: default avatardifince <dianaa@vmware.com>
parent 11179bf8
...@@ -18,7 +18,6 @@ import ( ...@@ -18,7 +18,6 @@ import (
"strconv" "strconv"
"github.com/edgexfoundry/edgex-go/internal/pkg/db" "github.com/edgexfoundry/edgex-go/internal/pkg/db"
dataBase "github.com/edgexfoundry/edgex-go/internal/pkg/db"
contract "github.com/edgexfoundry/go-mod-core-contracts/models" contract "github.com/edgexfoundry/go-mod-core-contracts/models"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/google/uuid" "github.com/google/uuid"
...@@ -256,15 +255,7 @@ func (c *Client) GetAllDevices() ([]contract.Device, error) { ...@@ -256,15 +255,7 @@ func (c *Client) GetAllDevices() ([]contract.Device, error) {
} }
func (c *Client) GetDevicesByProfileId(id string) ([]contract.Device, error) { func (c *Client) GetDevicesByProfileId(id string) ([]contract.Device, error) {
d, err := c.getDevicesByValue(db.Device + ":profile:" + id) return c.getDevicesByValue(db.Device + ":profile:" + id)
// XXX This is here only because test/db_metadata.go is inconsistent when testing for _not found_. It
// should always be checking for database.ErrNotFound but too often it is checking for nil
if len(d) == 0 {
err = dataBase.ErrNotFound
}
return d, err
} }
func (c *Client) GetDeviceById(id string) (contract.Device, error) { func (c *Client) GetDeviceById(id string) (contract.Device, error) {
...@@ -286,15 +277,7 @@ func (c *Client) GetDeviceByName(n string) (contract.Device, error) { ...@@ -286,15 +277,7 @@ func (c *Client) GetDeviceByName(n string) (contract.Device, error) {
} }
func (c *Client) GetDevicesByServiceId(id string) ([]contract.Device, error) { func (c *Client) GetDevicesByServiceId(id string) ([]contract.Device, error) {
d, err := c.getDevicesByValue(db.Device + ":service:" + id) return c.getDevicesByValue(db.Device + ":service:" + id)
// XXX This is here only because test/db_metadata.go is inconsistent when testing for _not found_. It
// should always be checking for database.ErrNotFound but too often it is checking for nil
if len(d) == 0 {
err = dataBase.ErrNotFound
}
return d, err
} }
func (c *Client) GetDevicesWithLabel(l string) ([]contract.Device, error) { func (c *Client) GetDevicesWithLabel(l string) ([]contract.Device, error) {
...@@ -439,15 +422,7 @@ func (c *Client) GetDeviceProfileByName(n string) (contract.DeviceProfile, error ...@@ -439,15 +422,7 @@ func (c *Client) GetDeviceProfileByName(n string) (contract.DeviceProfile, error
} }
func (c *Client) GetDeviceProfilesByCommandId(id string) ([]contract.DeviceProfile, error) { func (c *Client) GetDeviceProfilesByCommandId(id string) ([]contract.DeviceProfile, error) {
dp, err := c.getDeviceProfilesByValues(db.DeviceProfile + ":command:" + id) return c.getDeviceProfilesByValues(db.DeviceProfile + ":command:" + id)
// XXX This is here only because test/db_metadata.go is inconsistent when testing for _not found_. It
// should always be checking for database.ErrNotFound but too often it is checking for nil
if len(dp) == 0 {
err = dataBase.ErrNotFound
}
return dp, err
} }
// Get device profiles with the passed query // Get device profiles with the passed query
...@@ -798,13 +773,6 @@ func (c *Client) GetDeviceServicesByAddressableId(id string) ([]contract.DeviceS ...@@ -798,13 +773,6 @@ func (c *Client) GetDeviceServicesByAddressableId(id string) ([]contract.DeviceS
return []contract.DeviceService{}, err return []contract.DeviceService{}, err
} }
// XXX This should really return an ErrNotFound. It's not to be consistent with existing code
// assumptions
//
// if len(objects) == 0 {
// return []contract.DeviceService{}, dataBase.ErrNotFound
// }
d := make([]contract.DeviceService, len(objects)) d := make([]contract.DeviceService, len(objects))
for i, object := range objects { for i, object := range objects {
err = unmarshalDeviceService(object, &d[i]) err = unmarshalDeviceService(object, &d[i])
...@@ -988,27 +956,11 @@ func (c *Client) GetProvisionWatchersByIdentifier(k string, v string) (pw []cont ...@@ -988,27 +956,11 @@ func (c *Client) GetProvisionWatchersByIdentifier(k string, v string) (pw []cont
} }
func (c *Client) GetProvisionWatchersByServiceId(id string) ([]contract.ProvisionWatcher, error) { func (c *Client) GetProvisionWatchersByServiceId(id string) ([]contract.ProvisionWatcher, error) {
pw, err := c.getProvisionWatchersByValue(db.ProvisionWatcher + ":service:" + id) return c.getProvisionWatchersByValue(db.ProvisionWatcher + ":service:" + id)
// XXX This is here only because test/db_metadata.go is inconsistent when testing for _not found_. It
// should always be checking for database.ErrNotFound but too often it is checking for nil
if len(pw) == 0 {
err = dataBase.ErrNotFound
}
return pw, err
} }
func (c *Client) GetProvisionWatchersByProfileId(id string) ([]contract.ProvisionWatcher, error) { func (c *Client) GetProvisionWatchersByProfileId(id string) ([]contract.ProvisionWatcher, error) {
pw, err := c.getProvisionWatchersByValue(db.ProvisionWatcher + ":profile:" + id) return c.getProvisionWatchersByValue(db.ProvisionWatcher + ":profile:" + id)
// XXX This is here only because test/db_metadata.go is inconsistent when testing for _not found_. It
// should always be checking for database.ErrNotFound but too often it is checking for nil
if len(pw) == 0 {
err = dataBase.ErrNotFound
}
return pw, err
} }
func (c *Client) GetProvisionWatcherById(id string) (contract.ProvisionWatcher, error) { func (c *Client) GetProvisionWatcherById(id string) (contract.ProvisionWatcher, error) {
......
...@@ -877,7 +877,7 @@ func testDBDeviceProfile(t *testing.T, db interfaces.DBClient) { ...@@ -877,7 +877,7 @@ func testDBDeviceProfile(t *testing.T, db interfaces.DBClient) {
} }
deviceProfiles, err = db.GetDeviceProfilesByCommandId(uuid.New().String()) deviceProfiles, err = db.GetDeviceProfilesByCommandId(uuid.New().String())
if err != dataBase.ErrNotFound { if (err != nil && err != dataBase.ErrNotFound) || len(deviceProfiles) != 0 {
t.Fatalf("Error getting deviceProfiles %v", err) t.Fatalf("Error getting deviceProfiles %v", err)
} }
if len(deviceProfiles) != 0 { if len(deviceProfiles) != 0 {
...@@ -972,7 +972,7 @@ func testDBDevice(t *testing.T, db interfaces.DBClient) { ...@@ -972,7 +972,7 @@ func testDBDevice(t *testing.T, db interfaces.DBClient) {
} }
devices, err = db.GetDevicesByProfileId(uuid.New().String()) devices, err = db.GetDevicesByProfileId(uuid.New().String())
if err != dataBase.ErrNotFound { if (err != nil && err != dataBase.ErrNotFound) || len(devices) != 0 {
t.Fatalf("Error getting devices %v", err) t.Fatalf("Error getting devices %v", err)
} }
if len(devices) != 0 { if len(devices) != 0 {
...@@ -988,7 +988,7 @@ func testDBDevice(t *testing.T, db interfaces.DBClient) { ...@@ -988,7 +988,7 @@ func testDBDevice(t *testing.T, db interfaces.DBClient) {
} }
devices, err = db.GetDevicesByServiceId(uuid.New().String()) devices, err = db.GetDevicesByServiceId(uuid.New().String())
if err != dataBase.ErrNotFound { if (err != nil && err != dataBase.ErrNotFound) || len(devices) != 0 {
t.Fatalf("Error getting devices %v", err) t.Fatalf("Error getting devices %v", err)
} }
if len(devices) != 0 { if len(devices) != 0 {
...@@ -1095,7 +1095,7 @@ func testDBProvisionWatcher(t *testing.T, db interfaces.DBClient) { ...@@ -1095,7 +1095,7 @@ func testDBProvisionWatcher(t *testing.T, db interfaces.DBClient) {
} }
provisionWatchers, err = db.GetProvisionWatchersByServiceId(uuid.New().String()) provisionWatchers, err = db.GetProvisionWatchersByServiceId(uuid.New().String())
if err != dataBase.ErrNotFound { if (err != nil && err != dataBase.ErrNotFound) || len(provisionWatchers) != 0 {
t.Fatalf("Error getting provisionWatchers %v", err) t.Fatalf("Error getting provisionWatchers %v", err)
} }
if len(provisionWatchers) != 0 { if len(provisionWatchers) != 0 {
...@@ -1111,7 +1111,7 @@ func testDBProvisionWatcher(t *testing.T, db interfaces.DBClient) { ...@@ -1111,7 +1111,7 @@ func testDBProvisionWatcher(t *testing.T, db interfaces.DBClient) {
} }
provisionWatchers, err = db.GetProvisionWatchersByProfileId(uuid.New().String()) provisionWatchers, err = db.GetProvisionWatchersByProfileId(uuid.New().String())
if err != dataBase.ErrNotFound { if (err != nil && err != dataBase.ErrNotFound) || len(provisionWatchers) != 0 {
t.Fatalf("Error getting provisionWatchers %v", err) t.Fatalf("Error getting provisionWatchers %v", err)
} }
if len(provisionWatchers) != 0 { if len(provisionWatchers) != 0 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment