From 9efeba5b30673a1ccc4a9e26d80fa3fb54a135ab Mon Sep 17 00:00:00 2001 From: Tres Oelze Date: Wed, 8 Mar 2023 09:08:32 -0800 Subject: [PATCH] Handle boolean values in mongoutil.Config --- mongoutil/uri.go | 2 ++ mongoutil/uri_test.go | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mongoutil/uri.go b/mongoutil/uri.go index d00e02cb..b8b76fa8 100644 --- a/mongoutil/uri.go +++ b/mongoutil/uri.go @@ -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)}) } } } diff --git a/mongoutil/uri_test.go b/mongoutil/uri_test.go index 76d535bd..74142135 100644 --- a/mongoutil/uri_test.go +++ b/mongoutil/uri_test.go @@ -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 @@ -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) { @@ -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()) }