mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 23:41:22 +08:00
feat: add hrp.Run wrapper
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/cmd"
|
||||
)
|
||||
@@ -21,5 +22,7 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
os.Exit(cmd.Execute())
|
||||
exitCode := cmd.Execute()
|
||||
log.Info().Int("code", exitCode).Msg("hrp exit")
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
@@ -155,18 +155,20 @@ func IsErrorPredefined(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
func GetErrorCode(err error) (exitCode int) {
|
||||
func GetErrorCode(err error) (errCode int) {
|
||||
defer func() {
|
||||
log.Debug().Int("code", errCode).Msg("get error code")
|
||||
}()
|
||||
|
||||
if err == nil {
|
||||
return Success
|
||||
}
|
||||
|
||||
e := errors.Cause(err)
|
||||
if code, ok := errorsMap[e]; ok {
|
||||
exitCode = code
|
||||
errCode = code
|
||||
} else {
|
||||
exitCode = GeneralFail
|
||||
errCode = GeneralFail
|
||||
}
|
||||
|
||||
log.Warn().Int("code", exitCode).Msg("hrp exit")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -30,10 +30,11 @@ import (
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
// Run starts to run API test with default configs.
|
||||
func Run(testcases ...ITestCase) error {
|
||||
t := &testing.T{}
|
||||
return NewRunner(t).SetRequestsLogOn().Run(testcases...)
|
||||
// Run starts to run testcase with default configs.
|
||||
func Run(t *testing.T, testcases ...ITestCase) error {
|
||||
err := NewRunner(t).SetSaveTests(true).Run(testcases...)
|
||||
code.GetErrorCode(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// NewRunner constructs a new runner instance.
|
||||
@@ -204,11 +205,6 @@ func (r *HRPRunner) Run(testcases ...ITestCase) (err error) {
|
||||
// record execution data to summary
|
||||
s := newOutSummary()
|
||||
|
||||
defer func() {
|
||||
exitCode := code.GetErrorCode(err)
|
||||
log.Info().Int("code", exitCode).Msg("hrp runner exit code")
|
||||
}()
|
||||
|
||||
// load all testcases
|
||||
testCases, err := LoadTestCases(testcases...)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user