-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if list bridge output is empty #54
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test to accompany this change.
ovs/vswitch.go
Outdated
@@ -88,6 +88,9 @@ func (v *VSwitchService) ListBridges() ([]string, error) { | |||
return nil, err | |||
} | |||
|
|||
if string(output) == "" { | |||
return []string{}, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's return nil, nil
in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdlayher
Is it good to use nil
to instead []string{}
?
I think ListBridges() can return an empty array when someone tries to call it to get bridges length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, so nil is fine because whenever someone is working with a slice, they are either iterating it or trying to access a specific element, which they should only do after making a bounds check.
For the purposes, nil
and []string{}
are effectively equivalent, but I prefer nil because it truly conveys "nothing" is returned.
Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get it. Let me fix for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Looks like
strings.Split
will let VSwitch.ListBridges() result to []string{""} not []string{}if
ovs-vsctl list-br
output string is empty: "".