1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package rdsutils_test
import (
"net/url"
"regexp"
"testing"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/rds/rdsutils"
)
func TestConnectionStringBuilder(t *testing.T) {
cases := []struct {
user string
endpoint string
region string
dbName string
values url.Values
format rdsutils.ConnectionFormat
creds *credentials.Credentials
expectedErr error
expectedConnectRegex string
}{
{
user: "foo",
endpoint: "foo.bar",
region: "region",
dbName: "name",
format: rdsutils.NoConnectionFormat,
creds: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"),
expectedErr: rdsutils.ErrNoConnectionFormat,
expectedConnectRegex: "",
},
{
user: "foo",
endpoint: "foo.bar",
region: "region",
dbName: "name",
format: rdsutils.TCPFormat,
creds: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"),
expectedConnectRegex: `^foo:foo.bar\?Action=connect\&DBUser=foo.*\@tcp\(foo.bar\)/name`,
},
}
for _, c := range cases {
b := rdsutils.NewConnectionStringBuilder(c.endpoint, c.region, c.user, c.dbName, c.creds)
connectStr, err := b.WithFormat(c.format).Build()
if e, a := c.expectedErr, err; e != a {
t.Errorf("expected %v error, but received %v", e, a)
}
if re, a := regexp.MustCompile(c.expectedConnectRegex), connectStr; !re.MatchString(a) {
t.Errorf("expect %s to match %s", re, a)
}
}
}
|