Skip to content

Commit

Permalink
Include pre-uninstall script run into the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPologruto committed Sep 13, 2023
1 parent de7c018 commit c78ae7a
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions arduino/cores/packagemanager/package_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,29 +930,51 @@ func TestRunPostInstall(t *testing.T) {
// prepare dummy post install script
dir := paths.New(t.TempDir())

var scriptPath *paths.Path
var postScriptPath *paths.Path
var preScriptPath *paths.Path
var err error
if runtime.GOOS == "windows" {
scriptPath = dir.Join("post_install.bat")
postScriptPath = dir.Join("post_install.bat")
preScriptPath = dir.Join("pre_uninstall.bat")

err = scriptPath.WriteFile([]byte(
err = postScriptPath.WriteFile([]byte(
`@echo off
echo sent in stdout
echo sent in stderr 1>&2`))
require.NoError(t, err)
err = preScriptPath.WriteFile([]byte(
`@echo off
echo sent in stdout
echo sent in stderr 1>&2`))
} else {
scriptPath = dir.Join("post_install.sh")
err = scriptPath.WriteFile([]byte(
postScriptPath = dir.Join("post_install.sh")
preScriptPath = dir.Join("pre_uninstall.sh")
err = postScriptPath.WriteFile([]byte(
`#!/bin/sh
echo "sent in stdout"
echo "sent in stderr" 1>&2`))
require.NoError(t, err)
err = preScriptPath.WriteFile([]byte(
`#!/bin/sh
echo "sent in stdout"
echo "sent in stderr" 1>&2`))
}
require.NoError(t, err)
err = os.Chmod(scriptPath.String(), 0777)
err = os.Chmod(postScriptPath.String(), 0777)
require.NoError(t, err)
err = os.Chmod(preScriptPath.String(), 0777)
require.NoError(t, err)
stdout, stderr, err := pme.RunPreOrPostScript(dir, "post_install")
require.NoError(t, err)

// `HasPrefix` because windows seem to add a trailing space at the end
require.Equal(t, "sent in stdout", strings.Trim(string(stdout), "\n\r "))
require.Equal(t, "sent in stderr", strings.Trim(string(stderr), "\n\r "))

stdout, stderr, err = pme.RunPreOrPostScript(dir, "pre_uninstall")
require.NoError(t, err)

// `HasPrefix` because windows seem to add a trailing space at the end
require.Equal(t, "sent in stdout", strings.Trim(string(stdout), "\n\r "))
require.Equal(t, "sent in stderr", strings.Trim(string(stderr), "\n\r "))
}

0 comments on commit c78ae7a

Please sign in to comment.