-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Postgres dialect parse password with spaces
- Loading branch information
Showing
2 changed files
with
62 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package xorm | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/xormplus/core" | ||
) | ||
|
||
func TestPostgresDialect(t *testing.T) { | ||
TestParse(t) | ||
} | ||
|
||
func TestParse(t *testing.T) { | ||
tests := []struct { | ||
in string | ||
expected string | ||
valid bool | ||
}{ | ||
{"postgres://auser:password@localhost:5432/db?sslmode=disable", "db", true}, | ||
{"postgresql://auser:password@localhost:5432/db?sslmode=disable", "db", true}, | ||
{"postg://auser:password@localhost:5432/db?sslmode=disable", "db", false}, | ||
{"postgres://auser:pass with space@localhost:5432/db?sslmode=disable", "db", true}, | ||
{"postgres:// auser : password@localhost:5432/db?sslmode=disable", "db", true}, | ||
{"postgres://%20auser%20:pass%20with%20space@localhost:5432/db?sslmode=disable", "db", true}, | ||
{"postgres://auser:パスワード@localhost:5432/データベース?sslmode=disable", "データベース", true}, | ||
{"dbname=db sslmode=disable", "db", true}, | ||
{"user=auser password=password dbname=db sslmode=disable", "db", true}, | ||
{"", "db", false}, | ||
{"dbname=db =disable", "db", false}, | ||
} | ||
|
||
driver := core.QueryDriver("postgres") | ||
|
||
for _, test := range tests { | ||
uri, err := driver.Parse("postgres", test.in) | ||
|
||
if err != nil && test.valid { | ||
t.Errorf("%q got unexpected error: %s", test.in, err) | ||
} else if err == nil && !reflect.DeepEqual(test.expected, uri.DbName) { | ||
t.Errorf("%q got: %#v want: %#v", test.in, uri.DbName, test.expected) | ||
} | ||
} | ||
} |