Skip to content

Commit e620152

Browse files
authored
Return an empty slice instead of an error if there is no station (#69)
* Return an empty slice instead of an error if there is no station * Update StationInfo() doc comment about empty slices
1 parent 7baef12 commit e620152

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func (c *Client) BSS(ifi *Interface) (*BSS, error) {
4949
}
5050

5151
// StationInfo retrieves all station statistics about a WiFi interface.
52+
//
53+
// Since v0.2.0: if there are no stations, an empty slice is returned instead
54+
// of an error.
5255
func (c *Client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
5356
return c.c.StationInfo(ifi)
5457
}

client_linux.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ func (c *client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
185185
return nil, err
186186
}
187187

188-
if len(msgs) == 0 {
189-
return nil, os.ErrNotExist
190-
}
191-
192188
stations := make([]*StationInfo, len(msgs))
193189
for i := range msgs {
194190
if stations[i], err = parseStationInfo(msgs[i].Data); err != nil {

client_linux_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,15 @@ func TestLinux_clientStationInfoNoMessagesIsNotExist(t *testing.T) {
256256
return nil, io.EOF
257257
})
258258

259-
_, err := c.StationInfo(&Interface{
259+
info, err := c.StationInfo(&Interface{
260260
Index: 1,
261261
HardwareAddr: net.HardwareAddr{0xe, 0xad, 0xbe, 0xef, 0xde, 0xad},
262262
})
263-
if !os.IsNotExist(err) {
264-
t.Fatalf("expected is not exist, got: %v", err)
263+
if err != nil {
264+
t.Fatalf("undexpected error: %v", err)
265+
}
266+
if !reflect.DeepEqual(info, []*StationInfo{}) {
267+
t.Fatalf("expected info to be an empty slice, got %v", info)
265268
}
266269
}
267270

0 commit comments

Comments
 (0)