Skip to content

Add ResourceModel.FindByVersion implementation for BadgerDB #217

@jim-junior

Description

@jim-junior

Description

Add a FindByVersion method for BadgerDB in

func (m *ResourceModel) FindByVersion(name string, resourceType string, version string) (types.Resource, error) {
from etcd to BadgerDB. This method is responsible for retrieving a specific historical version of a resource from the local key-value store and unmarshaling it into a types.Resource object.

Requirements

  • File Location: internal/models/resource.go
  • Transactionality: Use a BadgerDB View (read-only) transaction.
  • Key Retrieval:
    • Construct the versioned key using the pattern: /resources/{resourceType}/{name}/{version}.
    • Retrieve the []byte value associated with this specific versioned key.
  • Error Handling: * If the specific version key does not exist, return a descriptive "not found" error consistent with the current implementation.
    • Handle potential JSON unmarshaling errors.
  • Data Transformation: Successfully unmarshal the retrieved data into the types.Resource struct.
  • 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 FindByVersion method correctly retrieves historical records from BadgerDB based on the version suffix.
  • The method returns the expected types.Resource object for a valid version.
  • A "not found" error is returned if the resource name, type, or specific version does not exist.
  • Test Case implementation: A unit test is provided that:
    • Pre-populates an in-memory BadgerDB with multiple versions of a resource (e.g., /1, /2).
    • Successfully retrieves a specific version (e.g., version "1") and verifies the data.
    • Asserts that requesting a non-existent version returns the expected error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions