test memory: read metadata if -M flag is specified

This commit is contained in:
Nick Craig-Wood 2022-12-15 12:37:19 +00:00
parent ec3cee89d3
commit 43506f8086

View file

@ -29,6 +29,7 @@ var commandDefinition = &cobra.Command{
cmd.Run(false, false, command, func() error {
ctx := context.Background()
ci := fs.GetConfig(context.Background())
metadata := ci.Metadata && fsrc.Features().ReadMetadata
objects, _, _, err := operations.Count(ctx, fsrc)
if err != nil {
return err
@ -39,6 +40,13 @@ var commandDefinition = &cobra.Command{
runtime.ReadMemStats(&before)
var mu sync.Mutex
err = operations.ListFn(ctx, fsrc, func(o fs.Object) {
// Read the metadata so it gets cached in the object
if metadata {
_, err := fs.GetMetadata(ctx, o)
if err != nil {
fs.Errorf(o, "Failed to read metadata: %v", err)
}
}
mu.Lock()
objs = append(objs, o)
mu.Unlock()