From 99127b20885f14399c94b976bca2be208043a033 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 15 Dec 2022 18:23:57 -0500 Subject: [PATCH] wip --- pkg/utils/command/command_helper_test.go | 26 +++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/pkg/utils/command/command_helper_test.go b/pkg/utils/command/command_helper_test.go index b5a6bdd..713ea0c 100644 --- a/pkg/utils/command/command_helper_test.go +++ b/pkg/utils/command/command_helper_test.go @@ -1,13 +1,29 @@ package command import ( - "path/filepath" + "os" "testing" - "github.com/IceWhaleTech/CasaOS-Common/utils/constants" + "gotest.tools/assert" ) -func TestExecutePostStartScripts(t *testing.T) { - scriptDirectory := filepath.Join(constants.DefaultConfigPath, "start.d") - ExecuteScripts(scriptDirectory) +func TestExecuteScripts(t *testing.T) { + // make a temp directory + tmpDir, err := os.MkdirTemp("", "casaos-test-*") + assert.NilError(t, err) + defer os.RemoveAll(tmpDir) + + ExecuteScripts(tmpDir) + + // create a sample script under tmpDir + script := tmpDir + "/test.sh" + f, err := os.Create(script) + assert.NilError(t, err) + defer f.Close() + + // write a sample script + _, err = f.WriteString("#!/bin/bash\necho 123") + assert.NilError(t, err) + + ExecuteScripts(tmpDir) }