-
Notifications
You must be signed in to change notification settings - Fork 8
Add time-related query tests and enhance query result handling for da… #34
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
base: master
Are you sure you want to change the base?
Add time-related query tests and enhance query result handling for da… #34
Conversation
…te and time types
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds parsing support for four temporal scalar types (time, date, datetime, duration) in query result parsing, introduces four tests verifying returned temporal/duration values, renames two exported example test functions, and updates .gitignore to ignore Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Test as Tests (client_test.go)
participant Client as Go Client
participant Parser as QueryResult.parseScalar
participant DB as FalkorDB Server
Note over Test,Client: Test issues Cypher query returning temporal/duration scalar
Test->>Client: Execute query
Client->>DB: Send query
DB-->>Client: ResultSet (type tag + int64 payload)
Client->>Parser: parseScalar(cell)
alt VALUE_TIME / VALUE_DATE / VALUE_DATETIME
Parser-->>Parser: convert int64 -> time.Time (Unix / UnixMilli)
else VALUE_DURATION
Parser-->>Parser: convert int64 -> time.Duration (seconds)
end
Parser-->>Client: parsed value
Client-->>Test: Return record with parsed temporal/duration value
Test->>Test: Assert types/components
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks (2 passed, 3 warnings)❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)client_test.go (1)
🔇 Additional comments (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
client_test.go(2 hunks)query_result.go(3 hunks)
🧰 Additional context used
🪛 GitHub Actions: Go
client_test.go
[error] 315-317: TestGetTime failed due to panic: runtime error: invalid memory address or nil pointer dereference. Occurred in github.com/FalkorDB/falkordb-go.TestGetTime at client_test.go:317.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (go)
🔇 Additional comments (3)
query_result.go (2)
9-9: Good addition of time import for temporal data support.The import is necessary for the new temporal data parsing functionality.
348-355: Critical: Confirm and adjust temporal data parsing (DATE, DATETIME, TIME)
The client currently assumes DATE and DATETIME are encoded as seconds since the Unix epoch and TIME as milliseconds since the epoch. There’s no evidence in the codebase or comments to back up these units or semantics. If TIME represents a time-of-day-only value (e.g., milliseconds since midnight), the existing conversion will yield an incorrect full‐date timestamp. Please verify the server’s encoding and update the conversions accordingly.• File:
query_result.go, lines 348–355Suggested diff template:
case VALUE_TIME: - return time.UnixMilli(v.(int64)), nil + // TODO: confirm TIME encoding (e.g., ms since midnight vs. epoch ms) + // If TIME is a time-of-day, convert v.(int64) into hours/minutes/seconds only: + // ms := v.(int64) + // h := ms / 3_600_000 + // m := (ms % 3_600_000) / 60_000 + // s := (ms % 60_000) / 1_000 + // ns := (ms % 1_000) * int64(time.Millisecond) + // return time.Date(0, 1, 1, int(h), int(m), int(s), int(ns), time.UTC), nil + return time.UnixMilli(v.(int64)), nilclient_test.go (1)
6-6: Good addition of time import for temporal tests.The import is necessary for the new temporal data type testing.
| func TestGetDateTime(t *testing.T) { | ||
| q := "RETURN localdatetime({year : 1984}) as date" | ||
| res, err := graph.Query(q, nil, nil) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| res.Next() | ||
| r := res.Record() | ||
| dateTimeValue := r.GetByIndex(0).(time.Time) | ||
| assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value") | ||
| } |
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.
Add error handling and improve test robustness.
This test also needs proper error handling. Additionally, consider adding type assertion safety checks.
Apply this diff:
func TestGetDateTime(t *testing.T) {
q := "RETURN localdatetime({year : 1984}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
+ return
}
+ if res == nil {
+ t.Error("Query result is nil")
+ return
+ }
res.Next()
r := res.Record()
- dateTimeValue := r.GetByIndex(0).(time.Time)
+ val := r.GetByIndex(0)
+ dateTimeValue, ok := val.(time.Time)
+ if !ok {
+ t.Errorf("Expected time.Time, got %T", val)
+ return
+ }
assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value")
}📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func TestGetDateTime(t *testing.T) { | |
| q := "RETURN localdatetime({year : 1984}) as date" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { | |
| t.Error(err) | |
| } | |
| res.Next() | |
| r := res.Record() | |
| dateTimeValue := r.GetByIndex(0).(time.Time) | |
| assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value") | |
| } | |
| func TestGetDateTime(t *testing.T) { | |
| q := "RETURN localdatetime({year : 1984}) as date" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { | |
| t.Error(err) | |
| return | |
| } | |
| if res == nil { | |
| t.Error("Query result is nil") | |
| return | |
| } | |
| res.Next() | |
| r := res.Record() | |
| val := r.GetByIndex(0) | |
| dateTimeValue, ok := val.(time.Time) | |
| if !ok { | |
| t.Errorf("Expected time.Time, got %T", val) | |
| return | |
| } | |
| assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value") | |
| } |
🤖 Prompt for AI Agents
In client_test.go around lines 335 to 345, the test lacks error handling after
calling res.Next() and does not safely assert the type of the returned value.
Add a check for the boolean result of res.Next() to handle the case where no
record is returned, and verify the type assertion for r.GetByIndex(0) before
using it as time.Time. If the type assertion fails, report an error in the test.
This will make the test more robust and prevent panics.
| func TestGetDate(t *testing.T) { | ||
| q := "RETURN date({year : 1984}) as date" | ||
| res, err := graph.Query(q, nil, nil) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| res.Next() | ||
| r := res.Record() | ||
| dateValue := r.GetByIndex(0).(time.Time) | ||
| assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value") | ||
| } |
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.
Add error handling to prevent nil pointer dereference.
Similar to TestGetTime, this test needs proper error handling to prevent nil pointer dereference.
Apply this diff:
func TestGetDate(t *testing.T) {
q := "RETURN date({year : 1984}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
+ return
}
+ if res == nil {
+ t.Error("Query result is nil")
+ return
+ }
res.Next()
r := res.Record()
dateValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value")
}📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func TestGetDate(t *testing.T) { | |
| q := "RETURN date({year : 1984}) as date" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { | |
| t.Error(err) | |
| } | |
| res.Next() | |
| r := res.Record() | |
| dateValue := r.GetByIndex(0).(time.Time) | |
| assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value") | |
| } | |
| func TestGetDate(t *testing.T) { | |
| q := "RETURN date({year : 1984}) as date" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { | |
| t.Error(err) | |
| return | |
| } | |
| if res == nil { | |
| t.Error("Query result is nil") | |
| return | |
| } | |
| res.Next() | |
| r := res.Record() | |
| dateValue := r.GetByIndex(0).(time.Time) | |
| assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value") | |
| } |
🤖 Prompt for AI Agents
In client_test.go around lines 323 to 333, the test lacks error handling after
calling res.Next(), which can cause a nil pointer dereference if no record is
returned. Add a check for the boolean result of res.Next() and handle the case
where it returns false by calling t.Error with an appropriate message and
returning early from the test. This ensures the test safely handles empty
results before accessing the record.
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.
Pull Request Overview
This PR extends query result handling by adding support for temporal data types (date, time, and datetime) and adds corresponding tests.
- Added new constants and parsing logic in
parseScalarfor date, time, and datetime. - Introduced tests (
TestGetTime,TestGetDate,TestGetDateTime) to verify correct handling of temporal values.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| query_result.go | Added VALUE_DATETIME, VALUE_DATE, VALUE_TIME constants and parsing cases for each type. |
| client_test.go | Added tests to assert correct extraction of time, date, and datetime from query results. |
Comments suppressed due to low confidence (2)
client_test.go:336
- [nitpick] The alias
as dateis confusing in the datetime test. Consider usingas datetimeto clearly reflect the returned type.
q := "RETURN localdatetime({year : 1984}) as date"
client_test.go:320
- [nitpick] The
TestGetTimeonly checks the hour component. Consider adding assertions for minutes, seconds, and timezone to fully validate thetime.Timevalue.
assert.Equal(t, timeValue.Hour(), 12, "Unexpected Time value")
query_result.go
Outdated
| VALUE_MAP | ||
| VALUE_POINT | ||
| VALUE_VECTORF32 | ||
| VALUE_DATETIME // Deprecated, use VALUE_POINT instead |
Copilot
AI
Jul 9, 2025
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.
[nitpick] The VALUE_DATETIME constant is marked deprecated but is still actively parsed. Consider removing it or updating the comment to reflect current usage or migration plan.
| VALUE_DATETIME // Deprecated, use VALUE_POINT instead | |
| VALUE_DATETIME // Deprecated: Retained for backward compatibility. Migrate to VALUE_POINT where possible. |
| return time.Unix(v.(int64), 0), nil | ||
|
|
||
| case VALUE_DATE: | ||
| return time.Unix(v.(int64), 0), nil | ||
|
|
||
| case VALUE_TIME: | ||
| return time.UnixMilli(v.(int64)), nil |
Copilot
AI
Jul 9, 2025
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.
Directly asserting v.(int64) may panic if the stored value isn’t an int64. Use a safe type check (t, ok := v.(int64)) and return an error if the assertion fails.
| return time.Unix(v.(int64), 0), nil | |
| case VALUE_DATE: | |
| return time.Unix(v.(int64), 0), nil | |
| case VALUE_TIME: | |
| return time.UnixMilli(v.(int64)), nil | |
| timestamp, ok := v.(int64) | |
| if !ok { | |
| return nil, errors.New("expected int64 for VALUE_DATETIME") | |
| } | |
| return time.Unix(timestamp, 0), nil | |
| case VALUE_DATE: | |
| timestamp, ok := v.(int64) | |
| if !ok { | |
| return nil, errors.New("expected int64 for VALUE_DATE") | |
| } | |
| return time.Unix(timestamp, 0), nil | |
| case VALUE_TIME: | |
| timestamp, ok := v.(int64) | |
| if !ok { | |
| return nil, errors.New("expected int64 for VALUE_TIME") | |
| } | |
| return time.UnixMilli(timestamp), nil |
…LUE_DATETIME in query result constants
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.
Actionable comments posted: 0
🧹 Nitpick comments (6)
.gitignore (1)
38-39: OK to add .history/; effectively redundant with top-level allowlist.Given the leading "*" ignore and explicit allowlist, ".history/" and "Thumbs.db" are already ignored unless explicitly unignored elsewhere. Harmless to keep for clarity.
example_graph_test.go (5)
29-29: Prefer idiomatic Go name: ExampleFalkorDBNewTLS.Minor style tweak to MixedCaps improves discoverability in docs.
-func ExampleFalkorDBNew_tls() { +func ExampleFalkorDBNewTLS() {
7-7: Replace deprecated ioutil with os.ReadFile.
io/ioutilis deprecated; useos.ReadFileand drop the import.-import ( - "crypto/tls" - "crypto/x509" - "fmt" - "io/ioutil" - "log" - "os" - ... +import ( + "crypto/tls" + "crypto/x509" + "fmt" + "log" + "os" + ... ) @@ - // Load CA cert - caCert, err := ioutil.ReadFile(tls_cacert) + // Load CA cert + caCert, err := os.ReadFile(tls_cacert)Also applies to: 50-53
32-35: Fix typos in TLS comments.-// tls_cert - A a X.509 certificate to use for authenticating the server to connected clients, masters or cluster peers. The file should be PEM formatted -// tls_key - A a X.509 private key to use for authenticating the server to connected clients, masters or cluster peers. The file should be PEM formatted -// tls_cacert - A PEM encoded CA's certificate file +// tls_cert - An X.509 certificate to authenticate the server to connected clients, masters, or cluster peers. PEM formatted. +// tls_key - An X.509 private key to authenticate the server to connected clients, masters, or cluster peers. PEM formatted. +// tls_cacert - A PEM-encoded CA certificate file.
38-41: Use negation instead of equality for booleans.- // Skip if we dont have all files to properly connect - if tlsready == false { + // Skip if we don't have all files to properly connect + if !tlsready { return }
62-69: Avoid endorsing insecure TLS by default. Gate InsecureSkipVerify behind an env flag.Keeps the example safe-by-default while still allowing local testing.
- // InsecureSkipVerify controls whether a client verifies the - // server's certificate chain and host name. - // If InsecureSkipVerify is true, TLS accepts any certificate - // presented by the server and any host name in that certificate. - // In this mode, TLS is susceptible to man-in-the-middle attacks. - // This should be used only for testing. - clientTLSConfig.InsecureSkipVerify = true + // Enable only for local testing if explicitly requested. + // WARNING: Susceptible to MITM; do not use in production. + if os.Getenv("FALKORDB_ALLOW_INSECURE") != "" { + clientTLSConfig.InsecureSkipVerify = true + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.gitignore(1 hunks)example_graph_test.go(2 hunks)
🔇 Additional comments (1)
example_graph_test.go (1)
14-14: Rename to ExampleFalkorDB_SelectGraph looks good.Example recognition by
go testis preserved.
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.
Actionable comments posted: 4
♻️ Duplicate comments (2)
query_result.go (1)
349-361: Optional: guard type assertions to avoid panics.Direct v.(int64) will panic on unexpected payloads. Switch to safe assertions with errors.
Example:
case VALUE_DATETIME: - return time.Unix(v.(int64), 0).UTC(), nil + ts, ok := v.(int64) + if !ok { return nil, errors.New("expected int64 for VALUE_DATETIME") } + return time.Unix(ts, 0).UTC(), nilRepeat for VALUE_DATE, VALUE_TIME, VALUE_DURATION.
client_test.go (1)
335-345: Harden TestGetDateTime: fix assert order and add safety checks.Same issues as above.
func TestGetDateTime(t *testing.T) { q := "RETURN localdatetime({year : 1984}) as date" res, err := graph.Query(q, nil, nil) - if err != nil { - t.Error(err) - } - res.Next() - r := res.Record() - dateTimeValue := r.GetByIndex(0).(time.Time) - assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value") + if err != nil { t.Fatal(err) } + if res == nil { t.Fatal("Query result is nil") } + if !res.Next() { t.Fatal("empty result") } + r := res.Record() + val := r.GetByIndex(0) + dateTimeValue, ok := val.(time.Time) + if !ok { t.Fatalf("Expected time.Time, got %T", val) } + assert.Equal(t, 1984, dateTimeValue.Year(), "Unexpected DateTime value") }
🧹 Nitpick comments (1)
query_result.go (1)
52-56: Confirm wire protocol codes for new scalar types.These rely on iota ordering. If server enum values differ, parsing will break. Consider pinning explicit values or add a compile-time comment with the server mapping.
Would you like a follow-up diff that assigns explicit numeric values to all VALUE_* constants to harden protocol compatibility?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
client_test.go(2 hunks)query_result.go(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
client_test.go (1)
record.go (1)
Record(3-6)
🪛 GitHub Actions: Go
client_test.go
[error] 320-320: TestGetTime failed: Not equal: expected: 10, actual: 12. Unexpected Time value. Command: go test -v ./...
🔇 Additional comments (3)
query_result.go (2)
9-9: OK to import time.Needed for new temporal parsing.
358-361: Duration unit check.Code assumes server returns seconds. If server ever ships millis, this will be off by 1000x. Please confirm against FalkorDB PR #1126 and add a brief comment citing the server unit.
client_test.go (1)
6-6: OK to import time.Required for new temporal/duration tests.
| func TestGetTime(t *testing.T) { | ||
| q := "RETURN localtime({hour: 12}) AS time" | ||
| res, err := graph.Query(q, nil, nil) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| res.Next() | ||
| r := res.Record() | ||
| timeValue := r.GetByIndex(0).(time.Time) | ||
| assert.Equal(t, timeValue.Hour(), 12, "Unexpected Time value") | ||
| } |
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.
Harden TestGetTime: fix assert arg order and add error/empty checks.
Current failure stems from reversed assert args and potential timezone drift. After normalizing to UTC in parser, update the test for robustness.
func TestGetTime(t *testing.T) {
q := "RETURN localtime({hour: 12}) AS time"
res, err := graph.Query(q, nil, nil)
- if err != nil {
- t.Error(err)
- }
- res.Next()
- r := res.Record()
- timeValue := r.GetByIndex(0).(time.Time)
- assert.Equal(t, timeValue.Hour(), 12, "Unexpected Time value")
+ if err != nil { t.Fatal(err) }
+ if res == nil { t.Fatal("Query result is nil") }
+ if !res.Next() { t.Fatal("empty result") }
+ r := res.Record()
+ val := r.GetByIndex(0)
+ timeValue, ok := val.(time.Time)
+ if !ok { t.Fatalf("Expected time.Time, got %T", val) }
+ assert.Equal(t, 12, timeValue.Hour(), "Unexpected Time value")
}📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func TestGetTime(t *testing.T) { | |
| q := "RETURN localtime({hour: 12}) AS time" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { | |
| t.Error(err) | |
| } | |
| res.Next() | |
| r := res.Record() | |
| timeValue := r.GetByIndex(0).(time.Time) | |
| assert.Equal(t, timeValue.Hour(), 12, "Unexpected Time value") | |
| } | |
| func TestGetTime(t *testing.T) { | |
| q := "RETURN localtime({hour: 12}) AS time" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { t.Fatal(err) } | |
| if res == nil { t.Fatal("Query result is nil") } | |
| if !res.Next() { t.Fatal("empty result") } | |
| r := res.Record() | |
| val := r.GetByIndex(0) | |
| timeValue, ok := val.(time.Time) | |
| if !ok { t.Fatalf("Expected time.Time, got %T", val) } | |
| assert.Equal(t, 12, timeValue.Hour(), "Unexpected Time value") | |
| } |
🧰 Tools
🪛 GitHub Actions: Go
[error] 320-320: TestGetTime failed: Not equal: expected: 10, actual: 12. Unexpected Time value. Command: go test -v ./...
🤖 Prompt for AI Agents
In client_test.go around lines 311 to 321, the TestGetTime has reversed assert
args and lacks checks for query errors/empty results and type assertion; update
the test to (1) fail immediately on err from graph.Query, (2) ensure res.Next()
returned true and fail the test if not, (3) retrieve the record and safely
type-assert the first field with an ok check, (4) convert the obtained time to
UTC before asserting the hour, and (5) call assert.Equal with expected value
first (12) and actual value second to fix argument order.
| func TestGetDate(t *testing.T) { | ||
| q := "RETURN date({year: 1984, month: 1, day: 1}) as date" | ||
| res, err := graph.Query(q, nil, nil) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| res.Next() | ||
| r := res.Record() | ||
| dateValue := r.GetByIndex(0).(time.Time) | ||
| assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value") | ||
| } |
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.
Harden TestGetDate: fix assert order and add safety checks.
Mirror the handling from TestGetTime.
func TestGetDate(t *testing.T) {
q := "RETURN date({year: 1984, month: 1, day: 1}) as date"
res, err := graph.Query(q, nil, nil)
- if err != nil {
- t.Error(err)
- }
- res.Next()
- r := res.Record()
- dateValue := r.GetByIndex(0).(time.Time)
- assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value")
+ if err != nil { t.Fatal(err) }
+ if res == nil { t.Fatal("Query result is nil") }
+ if !res.Next() { t.Fatal("empty result") }
+ r := res.Record()
+ val := r.GetByIndex(0)
+ dateValue, ok := val.(time.Time)
+ if !ok { t.Fatalf("Expected time.Time, got %T", val) }
+ assert.Equal(t, 1984, dateValue.Year(), "Unexpected Date value")
}📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func TestGetDate(t *testing.T) { | |
| q := "RETURN date({year: 1984, month: 1, day: 1}) as date" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { | |
| t.Error(err) | |
| } | |
| res.Next() | |
| r := res.Record() | |
| dateValue := r.GetByIndex(0).(time.Time) | |
| assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value") | |
| } | |
| func TestGetDate(t *testing.T) { | |
| q := "RETURN date({year: 1984, month: 1, day: 1}) as date" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| if res == nil { | |
| t.Fatal("Query result is nil") | |
| } | |
| if !res.Next() { | |
| t.Fatal("empty result") | |
| } | |
| r := res.Record() | |
| val := r.GetByIndex(0) | |
| dateValue, ok := val.(time.Time) | |
| if !ok { | |
| t.Fatalf("Expected time.Time, got %T", val) | |
| } | |
| assert.Equal(t, 1984, dateValue.Year(), "Unexpected Date value") | |
| } |
🤖 Prompt for AI Agents
In client_test.go around lines 323 to 333, TestGetDate needs safety checks and
the correct assert order like TestGetTime: after Query ensure err is nil, verify
res.Next() returned true (fail the test if false), get the record and check it's
not nil, safely type-assert the value (handle non-time types), and use
assert.Equal(t, 1984, dateValue.Year(), ...) with expected value first; update
assertions and nil/type checks accordingly.
| func TestGetDuration(t *testing.T) { | ||
| q := "RETURN duration({hours: 2, minutes: 30}) AS duration" | ||
| res, err := graph.Query(q, nil, nil) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| res.Next() | ||
| r := res.Record() | ||
| durationValue := r.GetByIndex(0).(time.Duration) | ||
| expectedDuration := 2*time.Hour + 30*time.Minute | ||
| assert.Equal(t, durationValue, expectedDuration, "Unexpected Duration value") | ||
| } |
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.
Harden TestGetDuration: add error/empty checks and type assertion guard.
Also fix assert arg order for clarity.
func TestGetDuration(t *testing.T) {
q := "RETURN duration({hours: 2, minutes: 30}) AS duration"
res, err := graph.Query(q, nil, nil)
- if err != nil {
- t.Error(err)
- }
- res.Next()
- r := res.Record()
- durationValue := r.GetByIndex(0).(time.Duration)
- expectedDuration := 2*time.Hour + 30*time.Minute
- assert.Equal(t, durationValue, expectedDuration, "Unexpected Duration value")
+ if err != nil { t.Fatal(err) }
+ if res == nil { t.Fatal("Query result is nil") }
+ if !res.Next() { t.Fatal("empty result") }
+ r := res.Record()
+ val := r.GetByIndex(0)
+ durationValue, ok := val.(time.Duration)
+ if !ok { t.Fatalf("Expected time.Duration, got %T", val) }
+ expectedDuration := 2*time.Hour + 30*time.Minute
+ assert.Equal(t, expectedDuration, durationValue, "Unexpected Duration value")
}📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func TestGetDuration(t *testing.T) { | |
| q := "RETURN duration({hours: 2, minutes: 30}) AS duration" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { | |
| t.Error(err) | |
| } | |
| res.Next() | |
| r := res.Record() | |
| durationValue := r.GetByIndex(0).(time.Duration) | |
| expectedDuration := 2*time.Hour + 30*time.Minute | |
| assert.Equal(t, durationValue, expectedDuration, "Unexpected Duration value") | |
| } | |
| func TestGetDuration(t *testing.T) { | |
| q := "RETURN duration({hours: 2, minutes: 30}) AS duration" | |
| res, err := graph.Query(q, nil, nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| if res == nil { | |
| t.Fatal("Query result is nil") | |
| } | |
| if !res.Next() { | |
| t.Fatal("empty result") | |
| } | |
| r := res.Record() | |
| val := r.GetByIndex(0) | |
| durationValue, ok := val.(time.Duration) | |
| if !ok { | |
| t.Fatalf("Expected time.Duration, got %T", val) | |
| } | |
| expectedDuration := 2*time.Hour + 30*time.Minute | |
| assert.Equal(t, expectedDuration, durationValue, "Unexpected Duration value") | |
| } |
🤖 Prompt for AI Agents
In client_test.go around lines 347 to 358, the test assumes query succeeds, that
res has a record, and that the value type-asserts to time.Duration, and also
uses assert.Equal with args reversed; update the test to fail fast on query
error, check res.Next() result and t.Fatal/t.Fatalf if no record, retrieve the
value safely using a type assertion that checks the boolean ok and fails the
test if it's not a time.Duration, and call assert.Equal with expected value as
the first argument and actual value second for clearer failure messages.
| case VALUE_DATETIME: | ||
| return time.Unix(v.(int64), 0), nil | ||
|
|
||
| case VALUE_DATE: | ||
| return time.Unix(v.(int64), 0), nil | ||
|
|
||
| case VALUE_TIME: | ||
| return time.UnixMilli(v.(int64)), nil | ||
|
|
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.
Fix timezone drift: normalize temporal values to UTC.
Tests show hour mismatch for localtime; time.Unix/UnixMilli returns a Time in Local zone. Normalize to UTC to keep deterministic values across environments.
Apply:
case VALUE_DATETIME:
- return time.Unix(v.(int64), 0), nil
+ return time.Unix(v.(int64), 0).UTC(), nil
case VALUE_DATE:
- return time.Unix(v.(int64), 0), nil
+ return time.Unix(v.(int64), 0).UTC(), nil
case VALUE_TIME:
- return time.UnixMilli(v.(int64)), nil
+ return time.UnixMilli(v.(int64)).UTC(), nil📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| case VALUE_DATETIME: | |
| return time.Unix(v.(int64), 0), nil | |
| case VALUE_DATE: | |
| return time.Unix(v.(int64), 0), nil | |
| case VALUE_TIME: | |
| return time.UnixMilli(v.(int64)), nil | |
| case VALUE_DATETIME: | |
| return time.Unix(v.(int64), 0).UTC(), nil | |
| case VALUE_DATE: | |
| return time.Unix(v.(int64), 0).UTC(), nil | |
| case VALUE_TIME: | |
| return time.UnixMilli(v.(int64)).UTC(), nil |
🤖 Prompt for AI Agents
In query_result.go around lines 349 to 357, the temporal cases return time
values in the local zone causing timezone drift; update each return to normalize
to UTC by calling .UTC() on the constructed Time (e.g. time.Unix(v.(int64),
0).UTC(), and time.UnixMilli(v.(int64)).UTC()) so returned times are
deterministic across environments.
fix #32
Summary by CodeRabbit
New Features
Tests
Refactor
Chores