From fe66704aaffb8ad37ae34da9ca38e1a5d8265460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Mon, 23 Oct 2023 21:48:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20shell=20=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 1 + .gitlab-ci.yml | 1 + pkg/tools/system.go | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 829e84e0..70cc0059 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,5 +17,6 @@ jobs: - name: Set up environment run: | cp panel-example.conf .env + go run . artisan key:generate - name: Run tests run: go test ./... diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 03c85ae9..4350b054 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -44,6 +44,7 @@ unit_test: - apt-get update - apt-get install -y curl jq - cp panel-example.conf .env + - go run . artisan key:generate - go test -v -coverprofile=coverage.txt -covermode=atomic ./... build: diff --git a/pkg/tools/system.go b/pkg/tools/system.go index 10564ad1..80d47e74 100644 --- a/pkg/tools/system.go +++ b/pkg/tools/system.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/goravel/framework/facades" + "github.com/goravel/framework/support" ) // Write 写入文件 @@ -52,7 +53,11 @@ func Exec(shell string) string { output, err := cmd.CombinedOutput() if err != nil { - facades.Log().Errorf("[面板][Helpers] 执行命令 %s 失败: %s", shell, err.Error()) + if support.Env == support.EnvTest { + panic(err) + } else { + facades.Log().Errorf("[面板][Helpers] 执行命令 %s 失败: %s", shell, err.Error()) + } return "" } @@ -65,13 +70,21 @@ func ExecAsync(shell string) { err := cmd.Start() if err != nil { - facades.Log().Errorf("[面板][Helpers] 执行命令 %s 失败: %s", shell, err.Error()) + if support.Env == support.EnvTest { + panic(err) + } else { + facades.Log().Errorf("[面板][Helpers] 执行命令 %s 失败: %s", shell, err.Error()) + } } go func() { err := cmd.Wait() if err != nil { - facades.Log().Errorf("[面板][Helpers] 执行命令 %s 失败: %s", shell, err.Error()) + if support.Env == support.EnvTest { + panic(err) + } else { + facades.Log().Errorf("[面板][Helpers] 执行命令 %s 失败: %s", shell, err.Error()) + } } }() }