Skip to content

Commit

Permalink
update unit tests for unified config
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Oct 8, 2024
1 parent c8ecf72 commit 710f1cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
29 changes: 0 additions & 29 deletions storage/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,8 @@ import (
"os"
"strings"
"testing"

"github.com/mschuchard/vault-raft-backup/util"
)

const (
bucket = "my_bucket"
prefix = "my_prefix"
)

var (
backupAWSConfig = &util.AWSConfig{S3Prefix: prefix}
expectedConfig = awsConfig{s3Bucket: bucket, s3Prefix: prefix}
)

func TestNewAWSConfig(test *testing.T) {
_, err := newAWSConfig(backupAWSConfig)
if err == nil || err.Error() != "empty s3 bucket input setting" {
test.Errorf("expected error: empty s3 bucket input setting, actual %v", err)
}

backupAWSConfig.S3Bucket = bucket
config, err := newAWSConfig(backupAWSConfig)
if err != nil {
test.Errorf("constructor unexpectedly errored with %v", err)
}
if *config != expectedConfig {
test.Errorf("expected aws config values: %v", expectedConfig)
test.Errorf("actual aws config value: %v", *config)
}
}

func TestSnapshotS3Upload(test *testing.T) {
// test this fails at s3upload
os.Setenv("AWS_REGION", "us-west-1")
Expand Down
34 changes: 34 additions & 0 deletions storage/storage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package storage

import (
"testing"

"github.com/mschuchard/vault-raft-backup/util"
)

const (
object = "my_bucket"
prefix = "my_prefix"
)

var (
backupAWSConfig = &util.AWSConfig{S3Prefix: prefix}
expectedConfig = config{object: object, prefix: prefix}
)

func TestNewConfig(test *testing.T) {
_, err := NewConfig(backupAWSConfig)
if err == nil || err.Error() != "empty storage object input setting" {
test.Errorf("expected error: empty storage object input setting, actual %s", err)
}

backupAWSConfig.S3Bucket = object
config, err := NewConfig(backupAWSConfig)
if err != nil {
test.Errorf("constructor unexpectedly errored with %v", err)
}
if *config != expectedConfig {
test.Errorf("expected aws config values: %v", expectedConfig)
test.Errorf("actual aws config value: %v", *config)
}
}

0 comments on commit 710f1cc

Please sign in to comment.