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
Description
Add a
FindByVersionmethod for BadgerDB inconveyor/internal/models/resource.go
Line 180 in 2572f4c
etcdtoBadgerDB. This method is responsible for retrieving a specific historical version of a resource from the local key-value store and unmarshaling it into atypes.Resourceobject.Requirements
internal/models/resource.go/resources/{resourceType}/{name}/{version}.[]bytevalue associated with this specific versioned key.types.Resourcestruct.*badger.DBinstance.internal/models/resource_test.go.Success Criteria
FindByVersionmethod correctly retrieves historical records from BadgerDB based on the version suffix.types.Resourceobject for a valid version./1,/2).