Skip to content

Add ResourceModel.Delete implementation for BadgerDB #213

@jim-junior

Description

@jim-junior

Description

Add the Delete method implementation for BadgerDB in

func (m *ResourceModel) Delete(name string, resourceType string) error {

This method is responsible for removing a resource and its associated metadata from the local key-value store.

Requirements

  • File Location: internal/models/resource.go
  • Transactionality: Use a BadgerDB Update transaction to perform the deletion.
  • Key Generation: Utilize the existing key(name, resourceType) helper to identify the target record.
  • Deletion Scope: * Remove the primary resource key: /resources/{resourceType}/{name}.
    • Note: Ensure the implementation considers whether associated version keys (e.g., /resources/{resourceType}/{name}/1) should also be purged to prevent "orphan" data in the local KV store.
  • Error Handling: Gracefully handle cases where the key does not exist. While etcd's delete is idempotent, BadgerDB's txn.Delete returns an error if the key is not found; this should be handled to match current application expectations.
  • Dependency Injection: The method must use the *badger.DB instance injected into the ResourceModel.
  • Testing: A corresponding test case must be created in internal/models/resource_test.go.

Success Criteria

  • The Delete method successfully removes the specified resource from BadgerDB.
  • The method executes within an atomic write transaction.
  • The method does not crash or return unhandled errors if the resource is already missing.
  • Test Case implementation: A unit test is provided that:
    • Pre-populates an in-memory BadgerDB with a test resource.
    • Calls Delete for that specific resource.
    • Asserts that a subsequent Get or FindOne call for that key returns a "not found" error.
    • Verifies that no unexpected errors occur when deleting a non-existent key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions