Skip to content

Commit

Permalink
review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
coolwednesday committed Jan 8, 2025
1 parent 6ad8948 commit c200644
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func generateMongoURI(config *Config) (uri, host string, err error) {
}

func getDBHost(uri string) (host string, err error) {
parsedURL, err := url.Parse(uri)
parsedURL, err := url.ParseRequestURI(uri)
if err != nil {
return "", err
}
Expand Down
17 changes: 14 additions & 3 deletions pkg/gofr/datasource/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,23 @@ func TestGenerateMongoURI(t *testing.T) {
name: "Valid Config",
config: Config{
User: "admin",
Password: "password",
Password: "p@##word:",
Host: "localhost",
Port: 27017,
Database: "mydb",
},
expectedURI: "mongodb://admin:password@localhost:27017/mydb?authSource=admin",
expectedURI: "mongodb://admin:p%2540%2523%2523word%253A@localhost:27017/mydb?authSource=admin",
expectedHost: "localhost",
expectedError: "",
},
{
name: "Valid Config without authentication",
config: Config{
Host: "localhost",
Port: 27017,
Database: "mydb",
},
expectedURI: "mongodb://localhost:27017/mydb?authSource=admin",
expectedHost: "localhost",
expectedError: "",
},
Expand Down Expand Up @@ -150,7 +161,7 @@ func TestGetDBHost(t *testing.T) {
name: "Empty URI",
uri: "",
expected: "",
expectedErr: "incorrect URI for MongoDB",
expectedErr: "parse \"\": empty url",
},
{
name: "Malformed URI",
Expand Down

0 comments on commit c200644

Please sign in to comment.