Skip to content

Commit cc4fc16

Browse files
Include pre-uninstall script run into the unit test
1 parent 59af039 commit cc4fc16

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

Diff for: arduino/cores/packagemanager/package_manager_test.go

+44-24
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ func TestVariantAndCoreSelection(t *testing.T) {
921921
})
922922
}
923923

924-
func TestRunPostInstall(t *testing.T) {
924+
func TestRunScript(t *testing.T) {
925925
pmb := NewBuilder(nil, nil, nil, nil, "test")
926926
pm := pmb.Build()
927927
pme, release := pm.NewExplorer()
@@ -930,29 +930,49 @@ func TestRunPostInstall(t *testing.T) {
930930
// prepare dummy post install script
931931
dir := paths.New(t.TempDir())
932932

933-
var scriptPath *paths.Path
934-
var err error
935-
if runtime.GOOS == "windows" {
936-
scriptPath = dir.Join("post_install.bat")
937-
938-
err = scriptPath.WriteFile([]byte(
939-
`@echo off
940-
echo sent in stdout
941-
echo sent in stderr 1>&2`))
942-
} else {
943-
scriptPath = dir.Join("post_install.sh")
944-
err = scriptPath.WriteFile([]byte(
945-
`#!/bin/sh
946-
echo "sent in stdout"
947-
echo "sent in stderr" 1>&2`))
933+
type Test struct {
934+
testName string
935+
scriptName string
936+
}
937+
938+
tests := []Test{
939+
{
940+
testName: "PostInstallScript",
941+
scriptName: "post_install",
942+
},
943+
{
944+
testName: "PreUninstallScript",
945+
scriptName: "pre_uninstall",
946+
},
948947
}
949-
require.NoError(t, err)
950-
err = os.Chmod(scriptPath.String(), 0777)
951-
require.NoError(t, err)
952-
stdout, stderr, err := pme.RunPreOrPostScript(dir, "post_install")
953-
require.NoError(t, err)
954948

955-
// `HasPrefix` because windows seem to add a trailing space at the end
956-
require.Equal(t, "sent in stdout", strings.Trim(string(stdout), "\n\r "))
957-
require.Equal(t, "sent in stderr", strings.Trim(string(stderr), "\n\r "))
949+
for _, test := range tests {
950+
t.Run(test.testName, func(t *testing.T) {
951+
var scriptPath *paths.Path
952+
var err error
953+
if runtime.GOOS == "windows" {
954+
scriptPath = dir.Join(test.scriptName + ".bat")
955+
956+
err = scriptPath.WriteFile([]byte(
957+
`@echo off
958+
echo sent in stdout
959+
echo sent in stderr 1>&2`))
960+
} else {
961+
scriptPath = dir.Join(test.scriptName + ".sh")
962+
err = scriptPath.WriteFile([]byte(
963+
`#!/bin/sh
964+
echo "sent in stdout"
965+
echo "sent in stderr" 1>&2`))
966+
}
967+
require.NoError(t, err)
968+
err = os.Chmod(scriptPath.String(), 0777)
969+
require.NoError(t, err)
970+
stdout, stderr, err := pme.RunPreOrPostScript(dir, test.scriptName)
971+
require.NoError(t, err)
972+
973+
// `HasPrefix` because windows seem to add a trailing space at the end
974+
require.Equal(t, "sent in stdout", strings.Trim(string(stdout), "\n\r "))
975+
require.Equal(t, "sent in stderr", strings.Trim(string(stderr), "\n\r "))
976+
})
977+
}
958978
}

0 commit comments

Comments
 (0)