forked from mirror/go-sqlcipher
UPD: TestAuthCreateDatabase
* Renamed test * Implemented 'exists' test * WIP #580
This commit is contained in:
parent
183e7d61d1
commit
f7f8019102
|
@ -9,14 +9,13 @@ package sqlite3
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateAuthDatabase(t *testing.T) {
|
func TestAuthCreateDatabase(t *testing.T) {
|
||||||
tempFilename := TempFilename(t)
|
tempFilename := TempFilename(t)
|
||||||
fmt.Println(tempFilename) // debug
|
defer os.Remove(tempFilename)
|
||||||
//defer os.Remove(tempFilename) // Disable for debug
|
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", "file:"+tempFilename+"?_auth&_auth_user=admin&_auth_pass=admin")
|
db, err := sql.Open("sqlite3", "file:"+tempFilename+"?_auth&_auth_user=admin&_auth_pass=admin")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,16 +23,18 @@ func TestCreateAuthDatabase(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
var i int64
|
// Ping database
|
||||||
err = db.QueryRow("SELECT count(type) FROM sqlite_master WHERE type='table' AND name='sqlite_user';").Scan(&i)
|
if err := db.Ping(); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Logf("sqlite_user exists: %d", i)
|
|
||||||
|
|
||||||
_, err = db.Exec("SELECT auth_user_add('test', 'test', false);", nil)
|
var exists bool
|
||||||
|
err = db.QueryRow("select count(type) from sqlite_master WHERE type='table' and name='sqlite_user';").Scan(&exists)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
t.Fatal("failed to enable User Authentication")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue