Skip to content

Add BadgerDBDelete method for ResourceDefinitionModel #252

Description

@jim-junior

Description

Extend the ResourceDefinitionModel struct by adding a new standalone method called BadgerDBDelete. To avoid breaking changes across external system logic, do not refactor or replace the legacy etcd-based Delete implementation. This new capability will introduce standalone support to remove an existing resource definition payload directly from BadgerDB.

Requirements

  • File Location: internal/models/resource_definitions.go
  • Method Signature Strategy: Introduce a new method named BadgerDBDelete(name string) error on the ResourceDefinitionModel struct.
  • Transactionality: Execute the entire removal check and delete block inside a BadgerDB Update (write) transaction to ensure proper synchronization.
  • Key Generation: Generate the targeted key using the existing key(name) helper (i.e., /resource_definitions/{name}).
  • Existence Verification & Error Handling: * Prior to running the deletion call, explicitly verify whether the key exists inside BadgerDB by trying to retrieve it or using transaction methods.
    • If the key is not found, return a descriptive custom "not found" validation error matching the error context returned by the etcd-based predecessor.
  • Testing: Write a dedicated validation test suite inside internal/models/resource_definitions_test.go to prove standalone item removal mechanics.

Success Criteria

  • The BadgerDBDelete method is successfully added to the data layer model alongside legacy paths without modifying existing API signatures.
  • The operation checks key existence and performs deletion atomically inside a write-safe Update block.
  • Attempting to delete a definition name that doesn't exist returns the expected descriptive "not found" error.
  • Test Case implementation: A comprehensive unit test is provided that:
    • Seeds an isolated, in-memory BadgerDB instance with a temporary resource definition key and data payload.
    • Successfully calls BadgerDBDelete to strip the key from the dataset.
    • Confirms through a subsequent lookup that the removed key is no longer discoverable in the database.
    • Verifies that invoking the deletion method on an invalid configuration name securely reports the expected error constraint.

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