xk6-frostfs/internal/registry/obj_importer.go
Ekaterina Lebedeva fa240302de
All checks were successful
DCO action / DCO (pull_request) Successful in 46s
Tests and linters / Tests (1.21) (pull_request) Successful in 1m46s
Tests and linters / Tests (1.22) (pull_request) Successful in 1m50s
Tests and linters / Tests with -race (pull_request) Successful in 1m56s
Tests and linters / Lint (pull_request) Successful in 3m2s
[#154] Add registry import cli utility
* Currently, objects created in preset are never deleted.
  k6 deletes only objects from registry, if registry file
  is not provided k6 delete load fails.
* Added cli utility to import objects created in preset
  into registry so k6 can delete them normally.

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
2024-08-07 15:48:09 +03:00

32 lines
539 B
Go

package registry
import (
"encoding/json"
"os"
)
func ImportJSONPreGen(o *ObjRegistry, filename string) error {
f, err := os.ReadFile(filename)
if err != nil {
return err
}
var pregenInfo PreGenerateInfo
err = json.Unmarshal(f, &pregenInfo)
if err != nil {
return err
}
for _, obj := range pregenInfo.Objects {
if obj.Bucket != "" {
err = o.AddObject("", "", obj.Bucket, obj.Object, "")
} else {
err = o.AddObject(obj.Container, obj.Object, "", "", "")
}
if err != nil {
return err
}
}
return nil
}