Skip to content

Commit

Permalink
feat: add test case for option
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 committed Aug 25, 2020
1 parent 1d02c4e commit 827bbca
Show file tree
Hide file tree
Showing 2 changed files with 517 additions and 343 deletions.
18 changes: 15 additions & 3 deletions internal/db/storage/blob/s3/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/vdaas/vald/internal/unit"
)

// Option represents the functional option for client.
type Option func(c *client) error

var (
Expand All @@ -32,6 +33,7 @@ var (
}
)

// WithErrGroup returns the option to set the eg.
func WithErrGroup(eg errgroup.Group) Option {
return func(c *client) error {
if eg != nil {
Expand All @@ -41,6 +43,7 @@ func WithErrGroup(eg errgroup.Group) Option {
}
}

// WithSession returns the option to set the session.
func WithSession(sess *session.Session) Option {
return func(c *client) error {
if sess != nil {
Expand All @@ -50,13 +53,15 @@ func WithSession(sess *session.Session) Option {
}
}

// WithBucket returns the option to set bucket.
func WithBucket(bucket string) Option {
return func(c *client) error {
c.bucket = bucket
return nil
}
}

// WithMaxPartSize returns the option to set maxPartSize.
func WithMaxPartSize(size string) Option {
return func(c *client) error {
b, err := unit.ParseBytes(size)
Expand All @@ -72,6 +77,7 @@ func WithMaxPartSize(size string) Option {
}
}

// WithMaxChunkSize returns the option to set maxChunkSize.
func WithMaxChunkSize(size string) Option {
return func(c *client) error {
b, err := unit.ParseBytes(size)
Expand All @@ -87,20 +93,26 @@ func WithMaxChunkSize(size string) Option {
}
}

// WithReaderBackoff returns the option to set readerBackoffEnabled.
func WithReaderBackoff(enabled bool) Option {
return func(c *client) error {
c.readerBackoffEnabled = enabled
return nil
}
}

// WithReaderBackoffOpts returns the option to set readerBackoffOpts.
func WithReaderBackoffOpts(opts ...backoff.Option) Option {
return func(c *client) error {
if c.readerBackoffOpts == nil {
c.readerBackoffOpts = opts
if opts == nil {
return nil
}
if c.readerBackoffOpts != nil {
c.readerBackoffOpts = append(c.readerBackoffOpts, opts...)
return nil
}

c.readerBackoffOpts = append(c.readerBackoffOpts, opts...)
c.readerBackoffOpts = opts

return nil
}
Expand Down
Loading

0 comments on commit 827bbca

Please sign in to comment.