-
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 (#407)
fix(BRIDGE-10): escaping db path when creating connections
- Loading branch information
1 parent
3734c76
commit 890426e
Showing
2 changed files
with
51 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,47 @@ | ||
package sqlite3 | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestClient_DBConnectionSpecialCharacterPath(t *testing.T) { | ||
dbDirs := []string{ | ||
"#test", | ||
"test_test", | ||
"test#test#test", | ||
"test$test$test", | ||
} | ||
|
||
testingDir := t.TempDir() | ||
|
||
for _, dirName := range dbDirs { | ||
path := filepath.Join(testingDir, dirName) | ||
if err := os.MkdirAll(path, 0777); 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() | ||
} | ||
|
||
if err := client.Ping(); err != nil { | ||
fmt.Println("Could not ping test database, error: ", err) | ||
client.Close() | ||
t.FailNow() | ||
} | ||
|
||
if err := client.Close(); err != nil { | ||
fmt.Println("Could not close test database, error: ", err) | ||
t.FailNow() | ||
} | ||
} | ||
} |