Skip to content

Add ResourceModel.List implementation for BadgerDB #214

@jim-junior

Description

@jim-junior

Description

Add the List method BadgerDB implementation in

func (m *ResourceModel) List(resourceType string) ([]string, error) {
. This method is responsible for scanning the database for all keys associated with a specific resource type and returning a list of their names (keys).

Requirements

  • File Location: internal/models/resource.go
  • Transactionality: Use a BadgerDB View (read-only) transaction.
  • Prefix Scanning: * Utilize a BadgerDB Iterator to scan for keys starting with the prefix: /resources/{resourceType}/.
    • The implementation must ensure it only collects the primary resource keys and handles the logic to filter out or include versioned sub-keys based on the existing application expectations.
  • Data Extraction: Extract and collect the keys as a slice of strings ([]string).
  • 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 List method successfully performs a prefix scan on the BadgerDB store.
  • The method returns an accurate slice of keys belonging to the requested resourceType.
  • The iterator is correctly closed/deferred to prevent memory leaks.
  • Test Case implementation: A unit test is provided that:
    • Pre-populates an in-memory BadgerDB with multiple resources of different types.
    • Calls List for a specific type.
    • Asserts that the returned slice contains all expected keys for that type and none from others.
    • Verifies the behavior when no resources of that type exist (should return an empty slice or error consistent with current behavior).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions