Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pbm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/google/go-cmp/cmp"

"github.com/percona/percona-backup-mongodb/pbm/storage"
"github.com/percona/percona-backup-mongodb/pbm/storage/azure"
"github.com/percona/percona-backup-mongodb/pbm/storage/fs"
"github.com/percona/percona-backup-mongodb/pbm/storage/gcs"
Expand Down Expand Up @@ -207,6 +208,18 @@ func TestIsSameStorage(t *testing.T) {
})
}

func TestCastError(t *testing.T) {
t.Run("S3", func(t *testing.T) {
cfg := StorageConf{Type: storage.S3}

err := cfg.Cast()
if err == nil {
t.Errorf("Cast did not raise an error")
}

})
}

func boolPtr(b bool) *bool {
return &b
}
3 changes: 3 additions & 0 deletions pbm/storage/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func (cfg *Config) IsSameStorage(other *Config) bool {
}

func (cfg *Config) Cast() error {
if cfg == nil {
return errors.New("missing filesystem configuration with filesystem storage type")
}
if cfg.Path == "" {
return errors.New("path can't be empty")
}
Expand Down
5 changes: 4 additions & 1 deletion pbm/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (

//nolint:lll
type Config struct {
Region string `bson:"region" json:"region" yaml:"region"`
Region string `bson:"region,omitempty" json:"region,omitempty" yaml:"region,omitempty"`
EndpointURL string `bson:"endpointUrl,omitempty" json:"endpointUrl" yaml:"endpointUrl,omitempty"`
EndpointURLMap map[string]string `bson:"endpointUrlMap,omitempty" json:"endpointUrlMap,omitempty" yaml:"endpointUrlMap,omitempty"`
ForcePathStyle *bool `bson:"forcePathStyle,omitempty" json:"forcePathStyle,omitempty" yaml:"forcePathStyle,omitempty"`
Expand Down Expand Up @@ -200,6 +200,9 @@ func (cfg *Config) IsSameStorage(other *Config) bool {
}

func (cfg *Config) Cast() error {
if cfg == nil {
return errors.New("missing S3 configuration with S3 storage type")
}
if cfg.Region == "" {
cfg.Region = defaultS3Region
}
Expand Down
11 changes: 11 additions & 0 deletions pbm/storage/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@
t.Error("expected not to be equal when updating credentials")
}
})

t.Run("Cast succeeds", func(t *testing.T) {
if opts.Region != "" {
t.Error("Start value is not ''")
}
opts.Cast()

Check failure on line 170 in pbm/storage/s3/s3_test.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

Error return value of `opts.Cast` is not checked (errcheck)

if opts.Region != "us-east-1" {
t.Error("Default value should be set on Cast")
}
})
}

func TestRetryer(t *testing.T) {
Expand Down
Loading