diff --git a/.vscode/settings.json b/.vscode/settings.json index 67cdf77..05f4970 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,12 @@ { "cSpell.words": [ + "charsets", "menv", "MINIT", + "mlog", "mtmpl", - "munit" + "munit", + "shellquote", + "simplifiedchinese" ] } \ No newline at end of file diff --git a/pkg/mexec/manager.go b/pkg/mexec/manager.go index 8cb24c3..57936fa 100644 --- a/pkg/mexec/manager.go +++ b/pkg/mexec/manager.go @@ -158,7 +158,7 @@ func (m *manager) Execute(opts ExecuteOptions) (err error) { } defer done() - opts.Logger.Print("minit: " + opts.Name + ": process started") + opts.Logger.Printf("minit: %s: process started", opts.Name) // streaming go opts.Logger.Out().ReadFrom(outPipe) @@ -170,23 +170,23 @@ func (m *manager) Execute(opts ExecuteOptions) (err error) { var code int if err != nil { + opts.Logger.Errorf("minit: %s: process exited with error: %s", opts.Name, err.Error()) if ee, ok := err.(*exec.ExitError); ok { code = ee.ExitCode() } else { - opts.Logger.Error("minit: " + opts.Name + ": process exited with error: " + err.Error()) return } } if checkSuccessCode(opts.SuccessCodes, code) { err = nil - opts.Logger.Print("minit: " + opts.Name + ": process exited successfully") + opts.Logger.Printf("minit: %s: exit code %d is in success_codes", opts.Name, code) return } err = fmt.Errorf("exit code: %d is not in success_codes", code) - opts.Logger.Error("minit: " + opts.Name + ": process exited with error: " + err.Error()) + opts.Logger.Errorf("minit: %s: process exited with error: %s", opts.Name, err.Error()) return } diff --git a/pkg/mexec/manager_test.go b/pkg/mexec/manager_test.go index 2d26864..a43525b 100644 --- a/pkg/mexec/manager_test.go +++ b/pkg/mexec/manager_test.go @@ -39,6 +39,7 @@ func TestNewManager(t *testing.T) { buf, err := os.ReadFile(filepath.Join("testdata", "test.out.log")) require.Contains(t, string(buf), "BBB") + require.NoError(t, err) go func() { time.Sleep(time.Second) @@ -55,9 +56,9 @@ func TestNewManager(t *testing.T) { Command: []string{ "sleep", "$AAA", }, - Logger: logger, + Logger: logger, + SuccessCodes: []int{0, 130, -1}, }) require.NoError(t, err) - - require.True(t, time.Now().Sub(t1) < time.Second*2) + require.True(t, time.Since(t1) < time.Second*2) }