-
Notifications
You must be signed in to change notification settings - Fork 7
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 #21 from btnguyen2k/dev
Prepare to release v0.2.1
- Loading branch information
Showing
21 changed files
with
3,997 additions
and
2,912 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
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package gocosmos | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestDriver_invalidConnectionString(t *testing.T) { | ||
name := "TestDriver_invalidConnectionString" | ||
driver := "gocosmos" | ||
{ | ||
db, _ := sql.Open(driver, "AccountEndpoint;AccountKey=demo") | ||
if err := db.Ping(); err == nil { | ||
t.Fatalf("%s failed: should have error", name) | ||
} | ||
} | ||
{ | ||
db, _ := sql.Open(driver, "AccountEndpoint=demo;AccountKey") | ||
if err := db.Ping(); err == nil { | ||
t.Fatalf("%s failed: should have error", name) | ||
} | ||
} | ||
{ | ||
db, _ := sql.Open(driver, "AccountEndpoint=demo;AccountKey=demo/invalid_key") | ||
if err := db.Ping(); err == nil { | ||
t.Fatalf("%s failed: should have error", name) | ||
} | ||
} | ||
} | ||
|
||
func TestDriver_missingEndpoint(t *testing.T) { | ||
name := "TestDriver_missingEndpoint" | ||
driver := "gocosmos" | ||
dsn := "AccountKey=demo" | ||
db, _ := sql.Open(driver, dsn) | ||
if err := db.Ping(); err == nil { | ||
t.Fatalf("%s failed: should have error", name) | ||
} | ||
} | ||
|
||
func TestDriver_missingAccountKey(t *testing.T) { | ||
name := "TestDriver_missingAccountKey" | ||
driver := "gocosmos" | ||
dsn := "AccountEndpoint=demo" | ||
db, _ := sql.Open(driver, dsn) | ||
if err := db.Ping(); err == nil { | ||
t.Fatalf("%s failed: should have error", name) | ||
} | ||
} | ||
|
||
func TestDriver_Conn(t *testing.T) { | ||
name := "TestDriver_Conn" | ||
db := _openDb(t, name) | ||
_, err := db.Conn(context.Background()) | ||
if err != nil { | ||
t.Fatalf("%s failed: %s", name, err) | ||
} | ||
} | ||
|
||
func TestDriver_Transaction(t *testing.T) { | ||
name := "TestDriver_Transaction" | ||
db := _openDb(t, name) | ||
if tx, err := db.BeginTx(context.Background(), nil); tx != nil || err == nil { | ||
t.Fatalf("%s failed: transaction is not supported yet", name) | ||
} else if strings.Index(err.Error(), "not supported") < 0 { | ||
t.Fatalf("%s failed: transaction is not supported yet / %s", name, err) | ||
} | ||
} | ||
|
||
func TestDriver_Open(t *testing.T) { | ||
name := "TestDriver_Open" | ||
db := _openDb(t, name) | ||
if err := db.Ping(); err != nil { | ||
t.Fatalf("%s failed: %s", name, err) | ||
} | ||
} | ||
|
||
func TestDriver_Close(t *testing.T) { | ||
name := "TestDriver_Close" | ||
db := _openDb(t, name) | ||
if err := db.Ping(); err != nil { | ||
t.Fatalf("%s failed: %s", name, err) | ||
} | ||
if err := db.Close(); err != nil { | ||
t.Fatalf("%s failed: %s", name, err) | ||
} | ||
} |
Oops, something went wrong.