@@ -12,7 +12,7 @@ import (
1212)
1313
1414func Test_defaultInitDatabase_ErrorWhenCannotCreatePasswordFile (t * testing.T ) {
15- err := defaultInitDatabase ("path_not_exists" , "path_not_exists" , "path_not_exists" , "Tom" , "Beer" , "" , os .Stderr )
15+ err := defaultInitDatabase ("path_not_exists" , "path_not_exists" , "path_not_exists" , "Tom" , "Beer" , "" , "" , os .Stderr )
1616
1717 assert .EqualError (t , err , "unable to write password file to path_not_exists/pwfile" )
1818}
@@ -49,7 +49,7 @@ func Test_defaultInitDatabase_ErrorWhenCannotStartInitDBProcess(t *testing.T) {
4949
5050 _ , _ = logFile .Write ([]byte ("and here are the logs!" ))
5151
52- err = defaultInitDatabase (binTempDir , runtimeTempDir , filepath .Join (runtimeTempDir , "data" ), "Tom" , "Beer" , "" , logFile )
52+ err = defaultInitDatabase (binTempDir , runtimeTempDir , filepath .Join (runtimeTempDir , "data" ), "Tom" , "Beer" , "" , "" , logFile )
5353
5454 assert .NotNil (t , err )
5555 assert .Contains (t , err .Error (), fmt .Sprintf ("unable to init database using '%s/bin/initdb -A password -U Tom -D %s/data --pwfile=%s/pwfile'" ,
@@ -72,7 +72,7 @@ func Test_defaultInitDatabase_ErrorInvalidLocaleSetting(t *testing.T) {
7272 }
7373 }()
7474
75- err = defaultInitDatabase (tempDir , tempDir , filepath .Join (tempDir , "data" ), "postgres" , "postgres" , "en_XY" , os .Stderr )
75+ err = defaultInitDatabase (tempDir , tempDir , filepath .Join (tempDir , "data" ), "postgres" , "postgres" , "en_XY" , "" , os .Stderr )
7676
7777 assert .NotNil (t , err )
7878 assert .Contains (t , err .Error (), fmt .Sprintf ("unable to init database using '%s/bin/initdb -A password -U postgres -D %s/data --pwfile=%s/pwfile --locale=en_XY'" ,
@@ -81,6 +81,27 @@ func Test_defaultInitDatabase_ErrorInvalidLocaleSetting(t *testing.T) {
8181 tempDir ))
8282}
8383
84+ func Test_defaultInitDatabase_ErrorInvalidEncodingSetting (t * testing.T ) {
85+ tempDir , err := os .MkdirTemp ("" , "prepare_database_test" )
86+ if err != nil {
87+ panic (err )
88+ }
89+
90+ defer func () {
91+ if err := os .RemoveAll (tempDir ); err != nil {
92+ panic (err )
93+ }
94+ }()
95+
96+ err = defaultInitDatabase (tempDir , tempDir , filepath .Join (tempDir , "data" ), "postgres" , "postgres" , "" , "invalid" , os .Stderr )
97+
98+ assert .NotNil (t , err )
99+ assert .Contains (t , err .Error (), fmt .Sprintf ("unable to init database using '%s/bin/initdb -A password -U postgres -D %s/data --pwfile=%s/pwfile --encoding=invalid'" ,
100+ tempDir ,
101+ tempDir ,
102+ tempDir ))
103+ }
104+
84105func Test_defaultInitDatabase_PwFileRemoved (t * testing.T ) {
85106 tempDir , err := os .MkdirTemp ("" , "prepare_database_test" )
86107 if err != nil {
0 commit comments