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

test that NodeHasLabel in TestGetOrCreateNode for creation #63

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"strconv"
"strings"
"sort"
)

// CreateNode creates a Node in the database.
Expand Down Expand Up @@ -256,6 +257,19 @@ func (n *Node) SetLabels(labels []string) error {
return nil // Success
}


func (n *Node) HasLabel(label string) bool {
labels, err := n.Labels()
if err != nil || len(labels) == 0 {
return false
}

sort.Strings(labels)
pos := sort.SearchStrings(labels, label)

return len(labels) != pos && labels[pos] == label
}

// NodesByLabel gets all nodes with a given label.
func (db *Database) NodesByLabel(label string) ([]*Node, error) {
uri := join(db.Url, "label", label, "nodes")
Expand Down
3 changes: 3 additions & 0 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func TestGetOrCreateNode(t *testing.T) {
if !created {
t.Fatal("Failed to create unique node")
}
if !n0.HasLabel(label) {
t.Fatal("Label was not applied to just created node.")
}
check0, err := n0.Properties()
if err != nil {
t.Fatal(err)
Expand Down