Skip to content

Commit

Permalink
Merge pull request #168 from mailgun/oelze/parse-bools-uri
Browse files Browse the repository at this point in the history
Handle boolean values in mongoutil.Config
  • Loading branch information
tresoelze authored Mar 13, 2023
2 parents 7f049c0 + 9efeba5 commit 2f66002
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions mongoutil/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func (c Config) URIWithOptions() string {
options = append(options, opt{key: toCamelCase(optName), value: strconv.Itoa(int(optVal))})
case string:
options = append(options, opt{key: toCamelCase(optName), value: optVal})
case bool:
options = append(options, opt{key: toCamelCase(optName), value: strconv.FormatBool(optVal)})
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions mongoutil/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func TestMongoURIFromJSON(t *testing.T) {
{"compressors": "snappy,zlib"},
{"replica_set": "v34_queue"},
{"read_preference": "secondaryPreferred"},
{"max_pool_size": 5}
{"max_pool_size": 5},
{"ssl": true}
]
}`)
var conf mongoutil.Config
Expand All @@ -113,7 +114,7 @@ func TestMongoURIFromJSON(t *testing.T) {
require.NoError(t, err)
require.Equal(t,
"mongodb://127.0.0.1:27017/foo?compressors=snappy,zlib&replicaSet=v34_queue&"+
"readPreference=secondaryPreferred&maxPoolSize=5", conf.URIWithOptions())
"readPreference=secondaryPreferred&maxPoolSize=5&ssl=true", conf.URIWithOptions())
}

func TestMongoURIFromYAML(t *testing.T) {
Expand All @@ -137,6 +138,6 @@ options:
require.NoError(t, err)
require.Equal(t, "mongodb://mongo-routes-n01-us-east-1.postgun.com:27017,"+
"mongo-routes-n02-us-east-1.postgun.com:27017,mongo-routes-n03-us-east-1.postgun.com:27017/mg_prod?"+
"tlsCertificateKeyFile=/etc/mailgun/ssl/mongo.pem&tlsCAFile=/etc/mailgun/ssl/mongo-ca.crt&"+
"ssl=true&tlsCertificateKeyFile=/etc/mailgun/ssl/mongo.pem&tlsCAFile=/etc/mailgun/ssl/mongo-ca.crt&"+
"replicaSet=routes&readPreferenceTags=dc:use1&readPreferenceTags=dc:usw2", conf.URIWithOptions())
}

0 comments on commit 2f66002

Please sign in to comment.