@@ -2,7 +2,6 @@ package extensionmgr
22
33import (
44 "context"
5- "os"
65 "path/filepath"
76 "testing"
87 "time"
@@ -59,9 +58,7 @@ echo 'null'
5958 t .Run (tt .name , func (t * testing.T ) {
6059 t .Parallel ()
6160 scriptPath := filepath .Join (tempDir , tt .name + ".sh" )
62- if err := os .WriteFile (scriptPath , []byte (tt .scriptContent ), 0755 ); err != nil {
63- t .Fatalf ("failed to write script: %v" , err )
64- }
61+ mustWriteFile (t , scriptPath , tt .scriptContent , 0755 )
6562
6663 executor := NewScriptExecutorWithTimeout (30 * time .Second )
6764 ctx := context .Background ()
@@ -110,9 +107,7 @@ func TestScriptExecutor_ContextCancellation_Recovery(t *testing.T) {
110107sleep 10
111108echo '{"version": "1.0.0"}'
112109`
113- if err := os .WriteFile (scriptPath , []byte (script ), 0755 ); err != nil {
114- t .Fatalf ("failed to write script: %v" , err )
115- }
110+ mustWriteFile (t , scriptPath , script , 0755 )
116111
117112 executor := NewScriptExecutorWithTimeout (30 * time .Second )
118113 ctx , cancel := context .WithCancel (context .Background ())
@@ -151,9 +146,7 @@ while [ $i -lt 100 ]; do
151146done
152147echo '{"success": true, "version": "1.0.0"}'
153148`
154- if err := os .WriteFile (scriptPath , []byte (script ), 0755 ); err != nil {
155- t .Fatalf ("failed to write script: %v" , err )
156- }
149+ mustWriteFile (t , scriptPath , script , 0755 )
157150
158151 // Use short timeout (500ms should be enough for process startup and kill)
159152 executor := NewScriptExecutorWithTimeout (500 * time .Millisecond )
@@ -198,9 +191,7 @@ func TestScriptExecutor_NonZeroExitCode_Recovery(t *testing.T) {
198191 t .Parallel ()
199192 scriptPath := filepath .Join (t .TempDir (), "exit_test.sh" )
200193 script := "#!/bin/sh\n exit " + tt .exitCode + "\n "
201- if err := os .WriteFile (scriptPath , []byte (script ), 0755 ); err != nil {
202- t .Fatalf ("failed to write script: %v" , err )
203- }
194+ mustWriteFile (t , scriptPath , script , 0755 )
204195
205196 executor := NewScriptExecutorWithTimeout (30 * time .Second )
206197 ctx := context .Background ()
@@ -229,9 +220,7 @@ func TestScriptExecutor_StderrOutputRecovery(t *testing.T) {
229220echo "error message" >&2
230221exit 1
231222`
232- if err := os .WriteFile (scriptPath , []byte (script ), 0755 ); err != nil {
233- t .Fatalf ("failed to write script: %v" , err )
234- }
223+ mustWriteFile (t , scriptPath , script , 0755 )
235224
236225 executor := NewScriptExecutorWithTimeout (30 * time .Second )
237226 ctx := context .Background ()
269258# Output valid JSON at the end
270259echo '{"version": "1.0.0", "message": "success"}'
271260`
272- if err := os .WriteFile (scriptPath , []byte (script ), 0755 ); err != nil {
273- t .Fatalf ("failed to write script: %v" , err )
274- }
261+ mustWriteFile (t , scriptPath , script , 0755 )
275262
276263 executor := NewScriptExecutorWithTimeout (30 * time .Second )
277264 ctx := context .Background ()
0 commit comments