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