-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(BRIDGE-10): escaping db path when creating connection
fix(BRIDGE-10): added tests
- Loading branch information
1 parent
3734c76
commit 50a15fe
Showing
2 changed files
with
64 additions
and
1 deletion.
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,60 @@ | ||
package sqlite3 | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"os" | ||
"os/user" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
const ( | ||
TestingDirectoryRoot = "/tmp/test_db_sqlite" | ||
) | ||
|
||
func TestClient_db_connection_special_characters_path(t *testing.T) { | ||
dbDirs := []string{ | ||
"#test", | ||
"test_test", | ||
"test#test#test", | ||
"test$test$test", | ||
} | ||
|
||
curUser, err := user.Current() | ||
if err != nil { | ||
fmt.Println("Could not get current current user, error: ", err) | ||
t.FailNow() | ||
} | ||
|
||
testingDir := filepath.Join(curUser.HomeDir, TestingDirectoryRoot) | ||
|
||
for _, dirName := range dbDirs { | ||
path := filepath.Join(testingDir, dirName) | ||
err = os.MkdirAll(path, 0777) | ||
if err != nil { | ||
fmt.Println("Could not create testing directory, error: ", err) | ||
t.FailNow() | ||
} | ||
|
||
filePath := filepath.Join(path, "test.db") | ||
|
||
client, err := sql.Open("sqlite3", getDatabaseConn("test", "test", filePath)) | ||
if err != nil { | ||
fmt.Println("Could not connect to test database, error: ", err) | ||
t.FailNow() | ||
} | ||
|
||
err = client.Ping() | ||
if err != nil { | ||
fmt.Println("Could not ping test database, error: ", err) | ||
t.FailNow() | ||
} | ||
} | ||
|
||
err = os.RemoveAll(TestingDirectoryRoot) | ||
if err != nil { | ||
fmt.Println("Could not remove testing directory, error: ", err) | ||
t.FailNow() | ||
} | ||
} |