Skip to content

Add BadgerDBGetPipeline method for PipelineModel #256

Description

@jim-junior

Description

Extend the PipelineModel struct by adding a new standalone query method called BadgerDBGetPipeline. To ensure backward compatibility across existing services and workers, do not refactor, rename, or drop the current etcd-based GetPipeline implementation. This method will introduce native support to fetch and unmarshal a specific pipeline configuration record directly from BadgerDB.

Requirements

  • File Location: internal/models/pipeline.go
  • Method Signature Strategy: Introduce a new method named BadgerDBGetPipeline(name string) (*types.Pipeline, error) on the PipelineModel struct.
  • Transactionality: Execute the fetch operation inside a BadgerDB View (read-only) transaction.
  • Key Generation: Calculate the target key using the established convention: /pipelines/{name}.
  • Data Retrieval & Deserialization:
    • Query the item matching the formatted key inside the transaction boundary.
    • Safely unpack or copy the raw byte payload from the database item context (e.g., using item.ValueCopy()) to comply with BadgerDB's standard memory lifecycle constraints.
    • Use the standard json.Unmarshal package to deserialize the JSON bytes back into a native *types.Pipeline struct reference.
  • Error Handling: If the target key does not exist inside BadgerDB (errors.Is(err, badger.ErrKeyNotFound)), bubble up a descriptive custom error: fmt.Errorf("pipeline not found") to guarantee strict error parity with the historical etcd implementation.
  • Testing: Create a dedicated unit test case inside internal/models/pipeline_test.go to validate standalone dataset retrieval and missing key handling using an ephemeral, in-memory BadgerDB instance.

Success Criteria

  • The BadgerDBGetPipeline method is added cleanly alongside legacy methods without altering current external structural signatures.
  • The engine executes data queries inside a localized read-only View transaction.
  • Requesting a non-existent pipeline identifier correctly surfaces the exact custom validation error: pipeline not found.
  • Test Case implementation: A comprehensive unit test is provided that:
    • Seeds an isolated, in-memory BadgerDB database with a pre-marshaled JSON configuration for a pipeline mock object.
    • Successfully calls BadgerDBGetPipeline using the designated object name.
    • Asserts that the returned type object matches the seeded fields exactly.
    • Confirms that passing a non-existent name string triggers the matching "not found" error.

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