Skip to content

Add BadgerDBFindAll method for ResourceDefinitionModel #253

Description

@jim-junior

Description

Extend the ResourceDefinitionModel struct by implementing a new standalone method called BadgerDBFindAll. To maintain strict backward compatibility across the rest of the engine, do not modify or deprecate the existing etcd-based FindAll implementation. This new method will introduce standalone support to iterate through and retrieve all resource definitions stored under the specified namespace prefix directly from BadgerDB.

Requirements

  • File Location: internal/models/resource_definitions.go
  • Method Signature Strategy: Introduce a new method named BadgerDBFindAll() ([]string, error) on the ResourceDefinitionModel struct.
  • Transactionality: Execute the prefix scan entirely within a BadgerDB View (read-only) transaction.
  • Prefix Scanning:
    • Instantiate a database iterator using default options via txn.NewIterator(badger.DefaultIteratorOptions).
    • Prefix scan using the standard byte boundary matching the legacy prefix namespace: /resource_definitions/.
  • Data Processing & Lifecycle Rules:
    • Loop through matched database items, retrieving the raw payloads safely.
    • Ensure you adhere to BadgerDB's item evaluation lifecycle rules by copying data safely out of the transaction scope (e.g., using item.ValueCopy()).
    • Append the string representation of each definition payload to a collection slice.
  • Error Handling: If no keys match the designated prefix context, return a descriptive custom error: fmt.Errorf("no resource definitions found") to guarantee parity with the etcd counterpart.
  • Testing: Write a dedicated unit test suite inside internal/models/resource_definitions_test.go to validate standalone dataset discovery.

Success Criteria

  • The BadgerDBFindAll method is successfully added to the data layer model alongside legacy paths without modifying existing API signatures.
  • The engine correctly sweeps keys using a BadgerDB transaction iterator targeted exclusively at the /resource_definitions/ byte prefix.
  • Searching a database containing zero records under the target prefix properly drops out with the custom "no resource definitions found" error validation.
  • Test Case implementation: A comprehensive unit test is provided that:
    • Seeds an isolated, in-memory BadgerDB instance with multiple disparate resource configuration payloads.
    • Successfully queries BadgerDBFindAll and verifies the array length matches the seeded database state perfectly.
    • Asserts that all returned payload strings match the values initially injected.
    • Confirms that calling the method against a completely clean database structure securely passes back the required error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    goPull requests that update go code

    Type

    Fields

    No fields configured for Task.

    Projects

    Status
    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions