Skip to content

Commit

Permalink
Return an empty slice instead of an error if there is no station (#69)
Browse files Browse the repository at this point in the history
* Return an empty slice instead of an error if there is no station
* Update StationInfo() doc comment about empty slices
  • Loading branch information
n-peugnet authored May 22, 2024
1 parent 7baef12 commit e620152
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (c *Client) BSS(ifi *Interface) (*BSS, error) {
}

// StationInfo retrieves all station statistics about a WiFi interface.
//
// Since v0.2.0: if there are no stations, an empty slice is returned instead
// of an error.
func (c *Client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
return c.c.StationInfo(ifi)
}
4 changes: 0 additions & 4 deletions client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ func (c *client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
return nil, err
}

if len(msgs) == 0 {
return nil, os.ErrNotExist
}

stations := make([]*StationInfo, len(msgs))
for i := range msgs {
if stations[i], err = parseStationInfo(msgs[i].Data); err != nil {
Expand Down
9 changes: 6 additions & 3 deletions client_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,15 @@ func TestLinux_clientStationInfoNoMessagesIsNotExist(t *testing.T) {
return nil, io.EOF
})

_, err := c.StationInfo(&Interface{
info, err := c.StationInfo(&Interface{
Index: 1,
HardwareAddr: net.HardwareAddr{0xe, 0xad, 0xbe, 0xef, 0xde, 0xad},
})
if !os.IsNotExist(err) {
t.Fatalf("expected is not exist, got: %v", err)
if err != nil {
t.Fatalf("undexpected error: %v", err)
}
if !reflect.DeepEqual(info, []*StationInfo{}) {
t.Fatalf("expected info to be an empty slice, got %v", info)
}
}

Expand Down

0 comments on commit e620152

Please sign in to comment.