Call Recording
Capture every API call with inputs, outputs, errors, and timing
Record every API call made to a service for test assertions.
recorder.Recorder · every call captured
Setup#
import "github.com/stackshy/cloudemu/v2/features/recorder"
rec := &recorder.Recorder{}
bucket := storage.NewBucket(aws.S3,
storage.WithRecorder(rec),
)Inspecting calls#
After running your code, inspect all recorded calls:
calls := rec.Calls()
for _, call := range calls {
fmt.Printf("%s.%s — duration: %v, error: %v\n",
call.Service, call.Operation, call.Duration, call.Error)
}Each Call contains:
Service— e.g., "storage", "compute"Operation— e.g., "PutObject", "RunInstances"Input— the operation inputOutput— the operation outputError— any error returnedTimestamp— when the call was madeDuration— how long it took
Fluent assertions#
Use the Matcher to filter and count calls in test assertions:
// Count calls to a specific operation
count := rec.Matcher().Service("storage").Operation("PutObject").Count()
assert.Equal(t, 3, count)
// Check that no errors occurred
rec.Matcher().Service("storage").AssertNoErrors(t)
// Filter by service
storageCalls := rec.Matcher().Service("storage").Calls()Reset#
Clear all recorded calls between tests:
rec.Reset()