Add time-related query tests and enhance query result handling for da…#34
Add time-related query tests and enhance query result handling for da…#34MuhammadQadora wants to merge 8 commits into
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. 📝 WalkthroughWalkthroughFour new test functions validate temporal and duration type parsing in graph query results. The Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
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.
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.
There was a problem hiding this comment.
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")
| VALUE_MAP | ||
| VALUE_POINT | ||
| VALUE_VECTORF32 | ||
| VALUE_DATETIME // Deprecated, use VALUE_POINT instead |
There was a problem hiding this comment.
[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 |
There was a problem hiding this comment.
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.
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.
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.
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.
| 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.
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.
|
Static Code Review 📊 ✅ All quality checks passed! |
| 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_DURATION: | ||
| // FalkorDB returns duration values in seconds, convert to nanoseconds | ||
| return time.Duration(v.(int64)) * time.Second, nil | ||
|
|
There was a problem hiding this comment.
logic: Unsafe type assertion v.(int64) may panic on non-integer time values. Use a type switch to handle int64 and float64.
| 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_DURATION: | |
| // FalkorDB returns duration values in seconds, convert to nanoseconds | |
| return time.Duration(v.(int64)) * time.Second, nil | |
| case VALUE_DATETIME, VALUE_DATE: | |
| var seconds float64 | |
| switch val := v.(type) { | |
| case int64: | |
| seconds = float64(val) | |
| case float64: | |
| seconds = val | |
| default: | |
| return nil, fmt.Errorf("unexpected type for DATETIME/DATE: %T", v) | |
| } | |
| sec := int64(seconds) | |
| nsec := int64((seconds - float64(sec)) * 1e9) | |
| return time.Unix(sec, nsec), nil | |
| case VALUE_TIME: | |
| ms, ok := v.(int64) | |
| if !ok { | |
| return nil, fmt.Errorf("unexpected type for TIME: %T", v) | |
| } | |
| return time.UnixMilli(ms), nil | |
| case VALUE_DURATION: | |
| // FalkorDB returns duration values in seconds, convert to nanoseconds | |
| var seconds float64 | |
| switch val := v.(type) { | |
| case int64: | |
| seconds = float64(val) | |
| case float64: | |
| seconds = val | |
| default: | |
| return nil, fmt.Errorf("unexpected type for DURATION: %T", v) | |
| } | |
| return time.Duration(seconds * float64(time.Second)), nil |
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| timeValue := val.(time.Time) |
There was a problem hiding this comment.
logic: Unsafe type assertion and improper error handling can cause a test panic. Use t.Fatal and a 'comma, ok' type assertion.
| if err != nil { | |
| t.Error(err) | |
| } | |
| timeValue := val.(time.Time) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| timeValue, ok := val.(time.Time) | |
| if !ok { | |
| t.Fatalf("Expected value to be of type time.Time, but got %T", val) | |
| } |
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (4)
client_test.go (3)
395-409: Add safety checks for empty results and type assertions.This test has the same issues as the previous temporal tests:
- Line 401: Check the return value of
res.Next().- Line 407: Use a safe type assertion.
🔎 Suggested improvements
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 } - res.Next() + if !res.Next() { + t.Fatal("expected at least one result") + } r := res.Record() val, err := r.GetByIndex(0) if err != nil { t.Error(err) + return } - dateTimeValue := val.(time.Time) + dateTimeValue, ok := val.(time.Time) + if !ok { + t.Fatalf("expected time.Time, got %T", val) + } assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value") }
379-393: Add safety checks for empty results and type assertions.Similar to TestGetTime, this test needs:
- Line 385: Check the return value of
res.Next()to handle empty results.- Line 391: Use a safe type assertion to prevent panics.
🔎 Suggested improvements
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) + return } - res.Next() + if !res.Next() { + t.Fatal("expected at least one result") + } r := res.Record() val, err := r.GetByIndex(0) if err != nil { t.Error(err) + return } - dateValue := val.(time.Time) + dateValue, ok := val.(time.Time) + if !ok { + t.Fatalf("expected time.Time, got %T", val) + } assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value") }
358-377: Add safety checks for empty results and type assertions.The test lacks two important checks:
Line 364:
res.Next()is called without checking its return value. If the query returns no results, subsequent calls will operate on nil/invalid data.Line 370: The type assertion
val.(time.Time)will panic if the value is not atime.Time.🔎 Suggested improvements
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) + return } - res.Next() + if !res.Next() { + t.Fatal("expected at least one result") + } r := res.Record() val, err := r.GetByIndex(0) if err != nil { t.Error(err) + return } - timeValue := val.(time.Time) + timeValue, ok := val.(time.Time) + if !ok { + t.Fatalf("expected time.Time, got %T", val) + } // Just verify we got a valid time.Time object // Note: The actual time values may not match due to timezone/parsing issues // This is a pre-existing issue in the TIME value parsing assert.IsType(t, time.Time{}, timeValue, "Should return a time.Time object") assert.False(t, timeValue.IsZero(), "Time should not be zero value") }query_result.go (1)
350-361: Fix unsafe type assertions and normalize to UTC.The temporal parsing cases have two issues:
Unsafe type assertions: Direct assertions
v.(int64)will panic if the server returns a different type (e.g.,float64). Use safe type checking instead.Timezone drift:
time.Unix()andtime.UnixMilli()return times in the local timezone, causing non-deterministic values across environments. Normalize to UTC for consistency.🔎 Proposed fixes
case VALUE_DATETIME: - return time.Unix(v.(int64), 0), nil + timestamp, ok := v.(int64) + if !ok { + return nil, fmt.Errorf("expected int64 for VALUE_DATETIME, got %T", v) + } + return time.Unix(timestamp, 0).UTC(), nil case VALUE_DATE: - return time.Unix(v.(int64), 0), nil + timestamp, ok := v.(int64) + if !ok { + return nil, fmt.Errorf("expected int64 for VALUE_DATE, got %T", v) + } + return time.Unix(timestamp, 0).UTC(), nil case VALUE_TIME: - return time.UnixMilli(v.(int64)), nil + timestamp, ok := v.(int64) + if !ok { + return nil, fmt.Errorf("expected int64 for VALUE_TIME, got %T", v) + } + return time.UnixMilli(timestamp).UTC(), nil case VALUE_DURATION: // FalkorDB returns duration values in seconds, convert to nanoseconds - return time.Duration(v.(int64)) * time.Second, nil + seconds, ok := v.(int64) + if !ok { + return nil, fmt.Errorf("expected int64 for VALUE_DURATION, got %T", v) + } + return time.Duration(seconds) * time.Second, nil
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
client_test.goquery_result.go
🧰 Additional context used
🧬 Code graph analysis (1)
client_test.go (1)
record.go (1)
Record(5-8)
⏰ 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 (1)
query_result.go (1)
9-9: LGTM!The time import is necessary for the new temporal type support.
| 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() | ||
| val, err := r.GetByIndex(0) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| durationValue := val.(time.Duration) | ||
| expectedDuration := 2*time.Hour + 30*time.Minute | ||
| assert.Equal(t, durationValue, expectedDuration, "Unexpected Duration value") | ||
| } |
There was a problem hiding this comment.
Add safety checks for empty results and type assertions.
This test needs the same improvements as the temporal tests:
- Line 417: Check the return value of
res.Next(). - Line 423: Use a safe type assertion for
time.Duration.
🔎 Suggested improvements
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)
+ return
}
- res.Next()
+ if !res.Next() {
+ t.Fatal("expected at least one result")
+ }
r := res.Record()
val, err := r.GetByIndex(0)
if err != nil {
t.Error(err)
+ return
}
- durationValue := val.(time.Duration)
+ 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, durationValue, expectedDuration, "Unexpected Duration value")
}🤖 Prompt for AI Agents
In client_test.go around lines 411-426, the test lacks safety checks: verify the
boolean result of res.Next() and fail the test if it returns false, and replace
the direct type assertion for time.Duration with a safe comma-ok assertion (fail
the test with a clear message if the type is not time.Duration); ensure you
still handle errors from r.GetByIndex as you already do.
fix #32
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.
PR Summary by Typo
Overview
This PR introduces comprehensive tests for time-related query results and enhances the client's ability to correctly parse and handle
TIME,DATE,DATETIME, andDURATIONdata types returned from the database. This ensures accurate representation of temporal values in the application.Key Changes
client_test.goto validate the parsing ofTIME,DATE,DATETIME, andDURATIONvalues.VALUE_constants inquery_result.goforDATETIME,DATE,TIME, andDURATIONtypes.query_result.goto convert these database temporal types into Go'stime.Timeandtime.Durationobjects..gitignoreto include.history/.Work Breakdown
To turn off PR summary, please visit Notification settings.