-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #673 from atomicules/tls-in-driver
Allow TLS connections in the driver
Showing
3 changed files
with
167 additions
and
32 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
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ package driver | |
import ( | ||
"flag" | ||
"fmt" | ||
"net/url" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/jmoiron/sqlx" | ||
|
@@ -78,3 +80,28 @@ func (s *testDriverSuite) TestTransaction(c *C) { | |
err = tx.Commit() | ||
c.Assert(err, IsNil) | ||
} | ||
|
||
func TestParseDSN(t *testing.T) { | ||
// List of DSNs to test and expected results | ||
// Use different numbered domains to more readily see what has failed - since we | ||
// test in a loop we get the same line number on error | ||
testDSNs := map[string]connInfo{ | ||
"user:password@localhost?db": connInfo{standardDSN: false, addr: "localhost", user: "user", password: "password", db: "db", params: url.Values{}}, | ||
"[email protected]?db": connInfo{standardDSN: false, addr: "1.domain.com", user: "user", password: "", db: "db", params: url.Values{}}, | ||
"user:[email protected]/db": connInfo{standardDSN: true, addr: "2.domain.com", user: "user", password: "password", db: "db", params: url.Values{}}, | ||
"user:[email protected]/db?ssl=true": connInfo{standardDSN: true, addr: "3.domain.com", user: "user", password: "password", db: "db", params: url.Values{"ssl": []string{"true"}}}, | ||
"user:[email protected]/db?ssl=custom": connInfo{standardDSN: true, addr: "4.domain.com", user: "user", password: "password", db: "db", params: url.Values{"ssl": []string{"custom"}}}, | ||
"user:[email protected]/db?unused=param": connInfo{standardDSN: true, addr: "5.domain.com", user: "user", password: "password", db: "db", params: url.Values{"unused": []string{"param"}}}, | ||
} | ||
|
||
for supplied, expected := range testDSNs { | ||
actual, err := parseDSN(supplied) | ||
if err != nil { | ||
t.Errorf("TestParseDSN failed. Got error: %s", err) | ||
} | ||
// Compare that with expected | ||
if !reflect.DeepEqual(actual, expected) { | ||
t.Errorf("TestParseDSN failed.\nExpected:\n%#v\nGot:\n%#v", expected, actual) | ||
} | ||
} | ||
} |