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

rewrite #3

Merged
merged 32 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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
50 changes: 0 additions & 50 deletions .circleci/config.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ get:
examples: get
@echo " "
@echo "Building the examples..."
$(GOBUILD) ./examples/redisgraph_tls_client/.
$(GOBUILD) ./examples/falkordb_tls_client/.

test: get
$(GOTEST) -race -covermode=atomic ./...
Expand Down
45 changes: 22 additions & 23 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link

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 and SelectGraph 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.

- db, _ := FalkorDBNew("0.0.0.0:6379")
+ db, err := FalkorDBNew("0.0.0.0:6379")
+ if err != nil {
+     t.Fatalf("Failed to connect to FalkorDB: %v", err)
+ }
- graph = db.SelectGraph("social")
+ graph, err = db.SelectGraph("social")
+ if err != nil {
+     t.Fatalf("Failed to select graph: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
db, _ := FalkorDBNew("0.0.0.0:6379")
graph = db.SelectGraph("social")
db, err := FalkorDBNew("0.0.0.0:6379")
if err != nil {
t.Fatalf("Failed to connect to FalkorDB: %v", err)
}
graph, err = db.SelectGraph("social")
if err != nil {
t.Fatalf("Failed to select graph: %v", err)
}

graph.Delete()

// Create 2 nodes connect via a single edge.
japan := NodeNew([]string{"Country"}, "j", nil)
Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

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

Ensure consistent typing for property values.

Explicitly typing property values as int64 improves consistency and prevents potential type mismatches during comparisons or operations.

}

func TestCreateQuery(t *testing.T) {
Expand Down Expand Up @@ -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)
Expand All @@ -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++
}

Expand All @@ -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")

Expand Down Expand Up @@ -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 }"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)")
Copy link

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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)
}

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.")
}

Expand Down
Loading