Skip to content

Add ResourceModel.FindAll implementation for BadgerDB #216

@jim-junior

Description

@jim-junior

Description

Add the FindAll method in

func (m *ResourceModel) FindAll(resourceType string) ([]string, error) {
impelementation for BadgerDB. This method is responsible for retrieving the full data content of all resources belonging to a specific type from the local key-value store.

Requirements

  • File Location: internal/models/resource.go
  • Transactionality: Use a BadgerDB View (read-only) transaction.
  • Prefix Scanning & Value Retrieval:
    • Utilize a BadgerDB Iterator to scan for all keys starting with the prefix: /resources/{resourceType}/.
    • Unlike the List method, this method must retrieve the Value associated with each key.
    • The implementation must include logic to filter out versioned sub-keys (e.g., /resources/type/name/1) to ensure only the primary resource objects are returned in the result set.
  • Data Extraction: Collect the values as a slice of strings (representing JSON data).
  • Error Handling: If no resources are found for the given type, return a "no resources found" error to maintain parity with the current implementation.
  • Dependency Injection: The method must use the injected *badger.DB instance.
  • Testing: A corresponding test case must be created in internal/models/resource_test.go.

Success Criteria

  • The FindAll method successfully iterates through BadgerDB and retrieves full resource values.
  • The method correctly filters out versioned keys and only returns primary resource data.
  • The iterator is correctly handled and closed to prevent resource leaks.
  • Test Case implementation: A unit test is provided that:
    • Pre-populates an in-memory BadgerDB with several resources of the same type (including versioned entries).
    • Calls FindAll for that type.
    • Asserts that the returned slice contains the correct number of items and the data matches the primary entries only.
    • Verifies that the method returns the expected error when scanning an empty resource type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Task.

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions