-
Notifications
You must be signed in to change notification settings - Fork 3
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
rewrite #3
rewrite #3
Changes from 1 commit
656d6c2
08b9f57
e0cfc1f
45e530e
1b4c7e3
92a8f1b
674be75
922dcfe
59f3af2
fe30683
5e7a972
c486250
7c9151e
fe3e283
a4baedd
c49e266
1a1b53e
61cca30
8973bcc
7eed759
032ddfa
5c3e9fe
a167a8d
d5c0c08
e3842d7
02c3b22
7113007
b9ef5eb
86da116
e9d6774
fb4c479
dbc2bbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,16 +4,15 @@ import ( | |||||||||||
"os" | ||||||||||||
"testing" | ||||||||||||
|
||||||||||||
"github.com/gomodule/redigo/redis" | ||||||||||||
"github.com/stretchr/testify/assert" | ||||||||||||
) | ||||||||||||
|
||||||||||||
var graph Graph | ||||||||||||
|
||||||||||||
func createGraph() { | ||||||||||||
conn, _ := redis.Dial("tcp", "0.0.0.0:6379") | ||||||||||||
conn.Do("FLUSHALL") | ||||||||||||
graph = GraphNew("social", conn) | ||||||||||||
db, _ := FalkorDBNew("0.0.0.0:6379") | ||||||||||||
graph = db.SelectGraph("social") | ||||||||||||
graph.Delete() | ||||||||||||
|
||||||||||||
// Create 2 nodes connect via a single edge. | ||||||||||||
japan := NodeNew([]string{"Country"}, "j", nil) | ||||||||||||
|
@@ -98,14 +97,14 @@ func checkQueryResults(t *testing.T, res *QueryResult) { | |||||||||||
assert.Equal(t, len(s.Properties), 4, "Person node should have 4 properties") | ||||||||||||
|
||||||||||||
assert.Equal(t, s.GetProperty("name"), "John Doe", "Unexpected property value.") | ||||||||||||
assert.Equal(t, s.GetProperty("age"), 33, "Unexpected property value.") | ||||||||||||
assert.Equal(t, s.GetProperty("age"), int64(33), "Unexpected property value.") | ||||||||||||
AviAvni marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
assert.Equal(t, s.GetProperty("gender"), "male", "Unexpected property value.") | ||||||||||||
assert.Equal(t, s.GetProperty("status"), "single", "Unexpected property value.") | ||||||||||||
|
||||||||||||
assert.Equal(t, e.GetProperty("year"), 2017, "Unexpected property value.") | ||||||||||||
assert.Equal(t, e.GetProperty("year"), int64(2017), "Unexpected property value.") | ||||||||||||
|
||||||||||||
assert.Equal(t, d.GetProperty("name"), "Japan", "Unexpected property value.") | ||||||||||||
assert.Equal(t, d.GetProperty("population"), 126800000, "Unexpected property value.") | ||||||||||||
assert.Equal(t, d.GetProperty("population"), int64(126800000), "Unexpected property value.") | ||||||||||||
Comment on lines
+79
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistent typing for property values. Explicitly typing property values as |
||||||||||||
} | ||||||||||||
|
||||||||||||
func TestCreateQuery(t *testing.T) { | ||||||||||||
|
@@ -177,7 +176,7 @@ func TestArray(t *testing.T) { | |||||||||||
res.Next() | ||||||||||||
r := res.Record() | ||||||||||||
assert.Equal(t, len(res.results), 1, "expecting 1 result record") | ||||||||||||
assert.Equal(t, []interface{}{0, 1, 2}, r.GetByIndex(0)) | ||||||||||||
assert.Equal(t, []interface{}{int64(0), int64(1), int64(2)}, r.GetByIndex(0)) | ||||||||||||
AviAvni marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
q = "unwind([0,1,2]) as x return x" | ||||||||||||
res, err = graph.Query(q) | ||||||||||||
|
@@ -189,7 +188,7 @@ func TestArray(t *testing.T) { | |||||||||||
i := 0 | ||||||||||||
for res.Next() { | ||||||||||||
r = res.Record() | ||||||||||||
AviAvni marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
assert.Equal(t, i, r.GetByIndex(0)) | ||||||||||||
assert.Equal(t, int64(i), r.GetByIndex(0)) | ||||||||||||
i++ | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
@@ -203,12 +202,12 @@ func TestArray(t *testing.T) { | |||||||||||
b := NodeNew([]string{"person"}, "", nil) | ||||||||||||
|
||||||||||||
a.SetProperty("name", "a") | ||||||||||||
a.SetProperty("age", 32) | ||||||||||||
a.SetProperty("array", []interface{}{0, 1, 2}) | ||||||||||||
a.SetProperty("age", int64(32)) | ||||||||||||
a.SetProperty("array", []interface{}{int64(0), int64(1), int64(2)}) | ||||||||||||
|
||||||||||||
b.SetProperty("name", "b") | ||||||||||||
b.SetProperty("age", 30) | ||||||||||||
b.SetProperty("array", []interface{}{3, 4, 5}) | ||||||||||||
b.SetProperty("age", int64(30)) | ||||||||||||
b.SetProperty("array", []interface{}{int64(3), int64(4), int64(5)}) | ||||||||||||
|
||||||||||||
assert.Equal(t, 1, len(res.results), "expecting 1 results record") | ||||||||||||
|
||||||||||||
|
@@ -248,8 +247,8 @@ func TestMap(t *testing.T) { | |||||||||||
r := res.Record() | ||||||||||||
mapval := r.GetByIndex(0).(map[string]interface{}) | ||||||||||||
|
||||||||||||
inner_map := map[string]interface{}{"x": []interface{}{1}} | ||||||||||||
expected := map[string]interface{}{"val_1": 5, "val_2": "str", "inner": inner_map} | ||||||||||||
inner_map := map[string]interface{}{"x": []interface{}{int64(1)}} | ||||||||||||
expected := map[string]interface{}{"val_1": int64(5), "val_2": "str", "inner": inner_map} | ||||||||||||
assert.Equal(t, mapval, expected, "expecting a map literal") | ||||||||||||
|
||||||||||||
q = "MATCH (a:Country) RETURN a { .name }" | ||||||||||||
|
@@ -295,20 +294,20 @@ func TestPath(t *testing.T) { | |||||||||||
assert.Equal(t, len(s.Properties), 4, "Person node should have 4 properties") | ||||||||||||
|
||||||||||||
assert.Equal(t, s.GetProperty("name"), "John Doe", "Unexpected property value.") | ||||||||||||
assert.Equal(t, s.GetProperty("age"), 33, "Unexpected property value.") | ||||||||||||
assert.Equal(t, s.GetProperty("age"), int64(33), "Unexpected property value.") | ||||||||||||
assert.Equal(t, s.GetProperty("gender"), "male", "Unexpected property value.") | ||||||||||||
assert.Equal(t, s.GetProperty("status"), "single", "Unexpected property value.") | ||||||||||||
|
||||||||||||
assert.Equal(t, e.GetProperty("year"), 2017, "Unexpected property value.") | ||||||||||||
assert.Equal(t, e.GetProperty("year"), int64(2017), "Unexpected property value.") | ||||||||||||
|
||||||||||||
assert.Equal(t, d.GetProperty("name"), "Japan", "Unexpected property value.") | ||||||||||||
assert.Equal(t, d.GetProperty("population"), 126800000, "Unexpected property value.") | ||||||||||||
assert.Equal(t, d.GetProperty("population"), int64(126800000), "Unexpected property value.") | ||||||||||||
|
||||||||||||
} | ||||||||||||
|
||||||||||||
func TestParameterizedQuery(t *testing.T) { | ||||||||||||
createGraph() | ||||||||||||
params := []interface{}{1, 2.3, "str", true, false, nil, []interface{}{0, 1, 2}, []interface{}{"0", "1", "2"}} | ||||||||||||
params := []interface{}{int64(1), 2.3, "str", true, false, nil, []interface{}{int64(0), int64(1), int64(2)}, []interface{}{"0", "1", "2"}} | ||||||||||||
q := "RETURN $param" | ||||||||||||
params_map := make(map[string]interface{}) | ||||||||||||
for index, param := range params { | ||||||||||||
|
@@ -323,25 +322,25 @@ func TestParameterizedQuery(t *testing.T) { | |||||||||||
} | ||||||||||||
|
||||||||||||
func TestCreateIndex(t *testing.T) { | ||||||||||||
res, err := graph.Query("CREATE INDEX ON :user(name)") | ||||||||||||
res, err := graph.Query("CREATE INDEX FOR (u:user) ON (u.name)") | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The modifications to the index creation and deletion queries to match FalkorDB's syntax are correctly implemented. However, error handling for these operations is missing. It's crucial to handle errors to ensure that the application can gracefully handle failures during index management operations. - res, err := graph.Query("CREATE INDEX FOR (u:user) ON (u.name)")
+ res, err := graph.Query("CREATE INDEX FOR (u:user) ON (u.name)")
+ if err != nil {
+ t.Errorf("Failed to create index: %v", err)
+ }
- res, err = graph.Query("DROP INDEX FOR (u:user) ON (u.name)")
+ res, err = graph.Query("DROP INDEX FOR (u:user) ON (u.name)")
+ if err != nil {
+ t.Errorf("Failed to drop index: %v", err)
+ } Also applies to: 331-331, 337-337, 343-343 Committable suggestion
Suggested change
|
||||||||||||
if err != nil { | ||||||||||||
t.Error(err) | ||||||||||||
} | ||||||||||||
assert.Equal(t, 1, res.IndicesCreated(), "Expecting 1 index created") | ||||||||||||
|
||||||||||||
res, err = graph.Query("CREATE INDEX ON :user(name)") | ||||||||||||
res, err = graph.Query("CREATE INDEX FOR (u:user) ON (u.name)") | ||||||||||||
if err != nil { | ||||||||||||
t.Error(err) | ||||||||||||
} | ||||||||||||
assert.Equal(t, 0, res.IndicesCreated(), "Expecting 0 index created") | ||||||||||||
|
||||||||||||
res, err = graph.Query("DROP INDEX ON :user(name)") | ||||||||||||
res, err = graph.Query("DROP INDEX FOR (u:user) ON (u.name)") | ||||||||||||
if err != nil { | ||||||||||||
t.Error(err) | ||||||||||||
} | ||||||||||||
assert.Equal(t, 1, res.IndicesDeleted(), "Expecting 1 index deleted") | ||||||||||||
|
||||||||||||
_, err = graph.Query("DROP INDEX ON :user(name)") | ||||||||||||
_, err = graph.Query("DROP INDEX FOR (u:user) ON (u.name)") | ||||||||||||
assert.Equal(t, err.Error(), "ERR Unable to drop index on :user(name): no such index.") | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
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.
Missing error handling for
FalkorDBNew
andSelectGraph
could lead to runtime issues if the database connection fails or the graph selection is unsuccessful. Consider adding error checks to prevent potential panics or undefined behavior.Committable suggestion