Issue 615: Add a new test to s3_test.go to check if NewS3Enumerator take DCTL_S3_envVar in charge

main
Louis TOUSSAINT 2021-07-01 17:47:38 +02:00
parent c882c769e8
commit 973b67f6d5
1 changed files with 47 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package enumerator
import (
"errors"
"os"
"reflect"
"testing"
@ -12,6 +13,52 @@ import (
"github.com/stretchr/testify/mock"
)
func TestS3Enumerator_NewS3Enumerator(t *testing.T) {
tests := []struct {
name string
config config.SupplierConfig
setEnv map[string]string
want string
}{
{
name: "test with no proxy env var",
config: config.SupplierConfig{
Key: "tfstate",
Backend: "s3",
Path: "terraform.tfstate",
},
setEnv: map[string]string{
"AWS_DEFAULT_REGION": "us-east-1",
},
want: "us-east-1",
},
{
name: "test with proxy env var",
config: config.SupplierConfig{
Key: "tfstate",
Backend: "s3",
Path: "terraform.tfstate",
},
setEnv: map[string]string{
"AWS_DEFAULT_REGION": "us-east-1",
"DCTL_S3_DEFAULT_REGION": "eu-west-3",
},
want: "eu-west-3",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for key, value := range tt.setEnv {
os.Setenv(key, value)
}
got := NewS3Enumerator(tt.config).client.(*s3.S3).Config.Region
if awssdk.StringValue(got) != tt.want {
t.Errorf("NewS3Enumerator().client.Config.Region got = %v, want %v", got, tt.want)
}
})
}
}
func TestS3Enumerator_Enumerate(t *testing.T) {
tests := []struct {
name string