Skip to content

Commit

Permalink
fix(connection): remove validation on sqlite database file extension
Browse files Browse the repository at this point in the history
it is up to the user to provide a valid file no matter the extension
  • Loading branch information
danvergara committed Jun 10, 2024
1 parent 70cfbf2 commit 6f70602
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
14 changes: 1 addition & 13 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ var (
ErrInvalidURLFormat = errors.New("invalid url")
// ErrInvalidDriver is used to notify that the provided driver is not supported.
ErrInvalidDriver = errors.New("invalid driver")
// ErrInvalidSqlite3Extension is used to notify that the selected file is not a sqlite3 file.
ErrInvalidSqlite3Extension = errors.New("invalid sqlite file extension")
// ErrSocketFileDoNotExist indicates that the given path to the socket files leads to no file.
ErrSocketFileDoNotExist = errors.New("socket file does not exist")
// ErrInvalidSocketFile indicates that the socket file must end with .sock as suffix.
Expand Down Expand Up @@ -212,11 +210,7 @@ func BuildConnectionFromOpts(opts command.Options) (string, command.Options, err
opts.DBName,
), opts, nil
case drivers.SQLite:
if hasValidSqlite3FileExtension(opts.DBName) {
return opts.DBName, opts, nil
}

return "", opts, fmt.Errorf("%s: %w", opts.URL, ErrInvalidSqlite3Extension)
return opts.DBName, opts, nil
default:
return "", opts, fmt.Errorf("%s: %w", opts.URL, ErrInvalidDriver)
}
Expand Down Expand Up @@ -369,12 +363,6 @@ func hasValidOraclePrefix(rawurl string) bool {
return strings.HasPrefix(rawurl, "oracle://")
}

func hasValidSqlite3FileExtension(fileName string) bool {
return strings.HasSuffix(fileName, "sqlite") || strings.HasSuffix(fileName, "db") ||
strings.HasSuffix(fileName, "db3") ||
strings.HasSuffix(fileName, "sqlite3")
}

func socketFileExists(socketFile string) bool {
info, err := os.Stat(socketFile)
if os.IsNotExist(err) {
Expand Down
8 changes: 3 additions & 5 deletions pkg/connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,17 +542,15 @@ func TestBuildConnectionFromOptsUserData(t *testing.T) {
},
},
{
name: "error - wrong sqlite3 file extension",
name: "success - valid sqlite3 file extension",
given: given{
opts: command.Options{
Driver: drivers.SQLite,
DBName: "users.wrong",
DBName: "users.rsd",
},
},
want: want{
uri: "users.wrong",
hasError: true,
err: ErrInvalidSqlite3Extension,
uri: "users.rsd",
},
},
}
Expand Down

0 comments on commit 6f70602

Please sign in to comment.