@@ -930,29 +930,51 @@ func TestRunPostInstall(t *testing.T) {
930
930
// prepare dummy post install script
931
931
dir := paths .New (t .TempDir ())
932
932
933
- var scriptPath * paths.Path
933
+ var postScriptPath * paths.Path
934
+ var preScriptPath * paths.Path
934
935
var err error
935
936
if runtime .GOOS == "windows" {
936
- scriptPath = dir .Join ("post_install.bat" )
937
+ postScriptPath = dir .Join ("post_install.bat" )
938
+ preScriptPath = dir .Join ("pre_uninstall.bat" )
937
939
938
- err = scriptPath .WriteFile ([]byte (
940
+ err = postScriptPath .WriteFile ([]byte (
941
+ `@echo off
942
+ echo sent in stdout
943
+ echo sent in stderr 1>&2` ))
944
+ require .NoError (t , err )
945
+ err = preScriptPath .WriteFile ([]byte (
939
946
`@echo off
940
947
echo sent in stdout
941
948
echo sent in stderr 1>&2` ))
942
949
} else {
943
- scriptPath = dir .Join ("post_install.sh" )
944
- err = scriptPath .WriteFile ([]byte (
950
+ postScriptPath = dir .Join ("post_install.sh" )
951
+ preScriptPath = dir .Join ("pre_uninstall.sh" )
952
+ err = postScriptPath .WriteFile ([]byte (
953
+ `#!/bin/sh
954
+ echo "sent in stdout"
955
+ echo "sent in stderr" 1>&2` ))
956
+ require .NoError (t , err )
957
+ err = preScriptPath .WriteFile ([]byte (
945
958
`#!/bin/sh
946
959
echo "sent in stdout"
947
960
echo "sent in stderr" 1>&2` ))
948
961
}
949
962
require .NoError (t , err )
950
- err = os .Chmod (scriptPath .String (), 0777 )
963
+ err = os .Chmod (postScriptPath .String (), 0777 )
964
+ require .NoError (t , err )
965
+ err = os .Chmod (preScriptPath .String (), 0777 )
951
966
require .NoError (t , err )
952
967
stdout , stderr , err := pme .RunPreOrPostScript (dir , "post_install" )
953
968
require .NoError (t , err )
954
969
955
970
// `HasPrefix` because windows seem to add a trailing space at the end
956
971
require .Equal (t , "sent in stdout" , strings .Trim (string (stdout ), "\n \r " ))
957
972
require .Equal (t , "sent in stderr" , strings .Trim (string (stderr ), "\n \r " ))
973
+
974
+ stdout , stderr , err = pme .RunPreOrPostScript (dir , "pre_uninstall" )
975
+ require .NoError (t , err )
976
+
977
+ // `HasPrefix` because windows seem to add a trailing space at the end
978
+ require .Equal (t , "sent in stdout" , strings .Trim (string (stdout ), "\n \r " ))
979
+ require .Equal (t , "sent in stderr" , strings .Trim (string (stderr ), "\n \r " ))
958
980
}
0 commit comments