-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CHP-3104] - Enable db client to accept options (#486)
- Loading branch information
1 parent
b497c8b
commit 1ce3c8e
Showing
6 changed files
with
72 additions
and
2 deletions.
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
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
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,18 @@ | ||
package util | ||
|
||
import "strings" | ||
|
||
func OptionsToMap(options string) map[string]string { | ||
opts := map[string]string{} | ||
options = strings.TrimSpace(options) | ||
|
||
if options != "" { | ||
kvPairs := strings.Split(options, " ") | ||
for _, entry := range kvPairs { | ||
kv := strings.SplitN(entry, "=", 2) | ||
opts[kv[0]] = kv[1] | ||
} | ||
} | ||
|
||
return opts | ||
} |
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,45 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOptionsToMap(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
expected map[string]string | ||
}{ | ||
{ | ||
name: "input is not empty string", | ||
input: "sslrootcert=rds-ca.pem sslmode=verify-full", | ||
expected: map[string]string{ | ||
"sslrootcert": "rds-ca.pem", | ||
"sslmode": "verify-full", | ||
}, | ||
}, | ||
{ | ||
name: "input is empty string", | ||
input: "", | ||
expected: map[string]string{}, | ||
}, | ||
{ | ||
name: "option has multiple equal signs", | ||
input: "sslrootcert=rds-ca.pem sslmode=verify-full option=value=value", | ||
expected: map[string]string{ | ||
"sslrootcert": "rds-ca.pem", | ||
"sslmode": "verify-full", | ||
"option": "value=value", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := OptionsToMap(tt.input) | ||
assert.Equal(t, tt.expected, result) | ||
}) | ||
} | ||
} |