File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ func (c *Credentials) EnvVars() map[string]string {
3939 envMap := make (map [string ]string )
4040
4141 for _ , v := range os .Environ () {
42- splitEnv := strings .Split (v , "=" )
42+ splitEnv := strings .SplitN (v , "=" , 2 )
4343 envMap [splitEnv [0 ]] = splitEnv [1 ]
4444 }
4545
Original file line number Diff line number Diff line change 11package vault
22
33import (
4+ "maps"
5+ "os"
46 "testing"
57
68 "github.com/hashicorp/vault/api"
@@ -27,3 +29,36 @@ func TestCredentials(t *testing.T) {
2729 }
2830
2931}
32+
33+ func TestEnvVars (t * testing.T ) {
34+ c := Credentials {
35+ Username : "user" ,
36+ Password : "passwd" ,
37+ }
38+ input := map [string ]string {
39+ "DB_URL" : "http://localhost:9001" ,
40+ "DB_URL_PARAMS" : "http://localhost:9001?sslmode=force" ,
41+ "DB_URL_MORE_PARAMS" : "http://localhost:9001?sslmode=force¶m1=val1&par2=something" ,
42+ }
43+ expected_output := map [string ]string {
44+ "Username" : c .Username ,
45+ "Password" : c .Password ,
46+ }
47+
48+ maps .Copy (expected_output , input )
49+ os .Clearenv ()
50+ for k , v := range input {
51+ defer os .Unsetenv (k )
52+ err := os .Setenv (k , v )
53+ if err != nil {
54+ t .Error (err )
55+ }
56+ }
57+
58+ result := c .EnvVars ()
59+
60+ if ! maps .Equal (expected_output , result ) {
61+ t .Errorf ("Result: %v is not equalt to expected result: %v" , result , expected_output )
62+ }
63+
64+ }
You can’t perform that action at this time.
0 commit comments