Description
Extend the DriverMessageModel struct by implementing a new standalone method called BadgerDBInsert. To prevent backward compatibility problems across the orchestration plane, do not refactor, rename, or drop the current etcd-based Insert function. This method introduces standalone support for serializing and storing an event or task payload directly inside BadgerDB.
Requirements
- File Location:
internal/models/messages.go
- Method Signature Strategy: Introduce a new method named
BadgerDBInsert(message craneTypes.DriverMessage) error on the DriverMessageModel struct.
- Transactionality: Execute both the data serialization checking and database storage updates within a single BadgerDB Update (write) transaction to handle execution safely.
- Serialization & Key Generation: * Generate the targeted storage key combining the existing runtime prefix struct member and the unique object key field:
m.Prefix + message.ID (yielding driver-messages/{message.ID}).
- Marshal the incoming
craneTypes.DriverMessage payload struct into valid JSON bytes using the standard json.Marshal library.
- Overwrite Safety / Duplicate Constraint: Prior to writing the new bytes, check if the calculated storage key already exists in BadgerDB. If it exists, return a descriptive custom error indicating that a message with that ID is already registered, preventing accidental overwrites.
- Testing: Add a dedicated unit test suite inside
internal/models/messages_test.go to validate successful data insertion paths, JSON payload storage structures, and key collision validation constraints utilizing an in-memory database instance.
Success Criteria
Description
Extend the
DriverMessageModelstruct by implementing a new standalone method calledBadgerDBInsert. To prevent backward compatibility problems across the orchestration plane, do not refactor, rename, or drop the current etcd-basedInsertfunction. This method introduces standalone support for serializing and storing an event or task payload directly inside BadgerDB.Requirements
internal/models/messages.goBadgerDBInsert(message craneTypes.DriverMessage) erroron theDriverMessageModelstruct.m.Prefix + message.ID(yieldingdriver-messages/{message.ID}).craneTypes.DriverMessagepayload struct into valid JSON bytes using the standardjson.Marshallibrary.internal/models/messages_test.goto validate successful data insertion paths, JSON payload storage structures, and key collision validation constraints utilizing an in-memory database instance.Success Criteria
BadgerDBInsertmethod is added cleanly alongside legacy functions without altering public method schemas.BadgerDBInsertusing a mock driver message.