Skip to content

fix: increased test coverage and improved filter query perf - #40

Merged
Akalanka47000 merged 1 commit into
mainfrom
test/increase-coverage
May 19, 2025
Merged

fix: increased test coverage and improved filter query perf#40
Akalanka47000 merged 1 commit into
mainfrom
test/increase-coverage

Conversation

@Akalanka47000

@Akalanka47000 Akalanka47000 commented May 19, 2025

Copy link
Copy Markdown
Member

Summary by Sourcery

Optimize filter query parsing, extend filter syntax support, refactor core query and soft-delete APIs, remove obsolete utilities, and significantly expand test coverage across plugins, sentinel, transactions, scheduling, deletion, and read operations.

New Features:

  • Support map-based and variadic field projections in Model.Select
  • Introduce experimental UseCluster method on Model
  • Extend filter query syntax with boolean, ObjectID, time, regex modifiers, and logical operators (and/or)

Bug Fixes:

  • Fix filter query parsing for values containing '='
  • Ensure correct casting of numeric, ObjectId, and time values in filter queries

Enhancements:

  • Simplify and optimize parseOperatorValue logic in filterquery util
  • Refactor Model.EnableSoftDelete and DisableSoftDelete to use pointer receivers
  • Remove deprecated utility functions (SetDefaults, setField, CastSlice)

Tests:

  • Expand plugin filter query tests for new operators and types
  • Add sentinel validation tests for equals rule
  • Add basic and client transaction tests
  • Add scheduling tests for unscheduling all queries
  • Add core delete tests for soft delete behavior
  • Add core read tests for GreaterThan, LessThan, Has, FindByID pointer, and variadic Select arguments

@sourcery-ai

sourcery-ai Bot commented May 19, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR refactors core query and projection logic for greater flexibility, optimizes filter query parsing for accurate type casting, cleans up legacy utility functions, and significantly expands test coverage across filtering, validation, transactions, scheduling, soft deletes, and read operations.

Sequence Diagram for Updated filterquery.parseOperatorValue Type Casting

sequenceDiagram
    participant Caller
    participant FQUtil as filterquery.util
    participant CastLib as cast
    participant MongoLib as primitive

    Caller->>FQUtil: parseOperatorValue(value, operator)
    FQUtil->>FQUtil: strVal = cast.ToString(value)
    FQUtil->>FQUtil: strVal = replaceOperator(strVal, operator)

    FQUtil->>CastLib: ToFloat64E(strVal)
    alt CastLib returns float64_val (no error)
        FQUtil-->>Caller: float64_val
    else CastLib returns error
        FQUtil->>MongoLib: ObjectIDFromHex(strVal)
        alt MongoLib returns objectId_val (no error)
            FQUtil-->>Caller: objectId_val
        else MongoLib returns error
            FQUtil->>CastLib: ToTimeE(strVal)
            alt CastLib returns time_val (no error)
                FQUtil-->>Caller: time_val
            else CastLib returns error
                FQUtil-->>Caller: strVal (as string)
            end
        end
    end
Loading

Updated Class Diagram for Model[T]

classDiagram
    class Model~T~ {
        +Select(fields ...any) Model~T~
        +EnableSoftDelete() void
        +DisableSoftDelete() void
        +softDeletePayload() primitive.M
        +UseCluster(connection *string) ClusterOp~T~
    }
Loading

Class Diagram: Removed Functions from utils Package

classDiagram
  class `utils.struct` {
    <<Module>>
    -setField(field reflect.Value, val string) error
    -SetDefaults(ptr any) error
  }
  class `utils.slice` {
    <<Module>>
    -CastSlice~T any~(slice []any) []T
  }
Loading

File-Level Changes

Change Details Files
Improved filter query parsing and type handling
  • Simplified parseOperatorValue to attempt float, ObjectID, then time conversions before defaulting to string
  • Fixed multi-‘=’ splitting in filterquery.Parse by joining value segments
plugins/filterquery/util.go
plugins/filterquery/filterquery.go
Refactor Model.Select to handle map, slice, and variadic inputs
  • Detect map argument and project fields directly
  • Use reflect.Type and cast.ToStringSlice for slice and variadic string support
  • Removed old slice/map branching and utils.CastSlice dependency
core/model.go
Adjust soft-delete methods to use pointer receivers
  • Change EnableSoftDelete and DisableSoftDelete to pointer receivers
  • Drop return values and streamline deletedAtFieldName assignment
core/model_query_delete.go
Clean up legacy utility functions
  • Remove SetDefaults and its helper setField from struct utils
  • Delete generic CastSlice in utils/slice.go
utils/struct.go
utils/slice.go
Reintroduce experimental UseCluster method
  • Add Model.UseCluster with pointer receiver in core/cluster.go
core/cluster.go
Expand test coverage across modules
  • Add boolean, ObjectID, time, regex, and complex operator cases in filter query tests
  • Introduce document-equals sentinel validation tests
  • Add basic and client transaction tests
  • Add unschedule, soft-delete, 'has' read-op, pointer-ID find, and variadic Select tests
tests/plugin_filter_query_test.go
tests/plugin_sentinel_test.go
tests/transaction_test.go
tests/core_schedule_test.go
tests/core_delete_test.go
tests/core_read_ops_test.go
tests/core_read_test.go
tests/core_read_select_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented May 19, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@Akalanka47000
Akalanka47000 merged commit ae9b515 into main May 19, 2025

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @Akalanka47000 - I've reviewed your changes - here's some feedback:

  • The new parseOperatorValue drops boolean handling, so you should explicitly parse "true"/"false" into booleans instead of leaving them as strings.
  • Your Select method assumes at least one argument, so add a guard for len(fields) == 0 to avoid a panic when no projection fields are passed.
  • EnableSoftDelete and DisableSoftDelete now use pointer receivers but other mutating methods use value receivers—consider standardizing on pointer receivers for all stateful model methods to avoid unexpected behavior.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant