diff --git a/cli/generator.go b/cli/generator.go index 5bf5a908..069aa177 100644 --- a/cli/generator.go +++ b/cli/generator.go @@ -81,6 +81,7 @@ func newGenSource(ctx *cli.Context, sizeField string) func() generator.Source { } opts := []generator.Option{ generator.WithCustomPrefix(ctx.String("prefix")), + generator.WithCustomName(ctx.String("obj.name")), generator.WithPrefixSize(prefixSize), } tokens := strings.Split(ctx.String(sizeField), ",") diff --git a/cli/get.go b/cli/get.go index b73cfb14..25b6ee4b 100644 --- a/cli/get.go +++ b/cli/get.go @@ -43,6 +43,10 @@ var getFlags = []cli.Flag{ Value: "10MiB", Usage: "Size of each generated object. Can be a number or 10KiB/MiB/GiB. All sizes are base 2 binary.", }, + cli.StringFlag{ + Name: "obj.name", + Usage: "Specify an object name", + }, cli.BoolFlag{ Name: "range", Usage: "Do ranged get operations. Will request with random offset and length.", @@ -51,7 +55,6 @@ var getFlags = []cli.Flag{ Name: "range-size", Usage: "Use a fixed range size while doing random range offsets with --range", }, - cli.IntFlag{ Name: "versions", Value: 1, diff --git a/pkg/generator/options.go b/pkg/generator/options.go index 749c9822..423d430c 100644 --- a/pkg/generator/options.go +++ b/pkg/generator/options.go @@ -19,6 +19,7 @@ package generator import ( "errors" + "fmt" "math/rand" ) @@ -27,6 +28,7 @@ import ( type Options struct { src func(o Options) (Source, error) customPrefix string + customName string random RandomOpts csv CsvOpts minSize int64 @@ -48,6 +50,16 @@ func (o Options) getSize(rng *rand.Rand) int64 { return GetExpRandSize(rng, o.minSize, o.totalSize) } +// getSize will return a size for an object. +func (o Options) getName(counter uint64, rng *rand.Rand) string { + if o.customName != "" { + return o.customName + } + var nBuf [16]byte + randASCIIBytes(nBuf[:], rng) + return fmt.Sprintf("%d.%s.rnd", counter, string(nBuf[:])) +} + func defaultOptions() Options { o := Options{ src: newRandom, @@ -115,6 +127,14 @@ func WithCustomPrefix(prefix string) Option { } } +// WithCustomName adds custom object name +func WithCustomName(name string) Option { + return func(o *Options) error { + o.customName = name + return nil + } +} + // WithPrefixSize sets prefix size. func WithPrefixSize(n int) Option { return func(o *Options) error { diff --git a/pkg/generator/random.go b/pkg/generator/random.go index 5a20dc40..e9b3a3f9 100644 --- a/pkg/generator/random.go +++ b/pkg/generator/random.go @@ -121,10 +121,8 @@ func newRandom(o Options) (Source, error) { func (r *randomSrc) Object() *Object { atomic.AddUint64(&r.counter, 1) - var nBuf [16]byte - randASCIIBytes(nBuf[:], r.rng) r.obj.Size = r.o.getSize(r.rng) - r.obj.setName(fmt.Sprintf("%d.%s.rnd", atomic.LoadUint64(&r.counter), string(nBuf[:]))) + r.obj.setName(r.o.getName(atomic.LoadUint64(&r.counter), r.rng)) // Reset scrambler r.obj.Reader = r.buf.Reset(r.obj.Size)