Skip to content
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

Merged
merged 3 commits into from
Jun 4, 2018
Merged

Check if list bridge output is empty #54

merged 3 commits into from
Jun 4, 2018

Conversation

chenyunchen
Copy link
Contributor

Looks like strings.Split will let VSwitch.ListBridges() result to []string{""} not []string{}
if ovs-vsctl list-br output string is empty: "".

Copy link
Contributor

@mdlayher mdlayher left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

@chenyunchen chenyunchen Jun 3, 2018

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@mdlayher mdlayher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mdlayher mdlayher merged commit 93b1811 into digitalocean:master Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants