mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
fix: boomer
This commit is contained in:
@@ -2,7 +2,6 @@ package hrp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -131,18 +130,18 @@ func (b *HRPBoomer) ConvertTestCasesToBoomerTasks(testcases ...ITestCase) (taskS
|
|||||||
return taskSlice
|
return taskSlice
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *HRPBoomer) ParseTestCases(testCases []*TestCase) []*TCase {
|
func (b *HRPBoomer) ParseTestCases(testCases []*TestCase) []*TestCase {
|
||||||
var parsedTestCases []*TCase
|
var parsedTestCases []*TestCase
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
caseRunner, err := b.hrpRunner.NewCaseRunner(tc)
|
caseRunner, err := b.hrpRunner.NewCaseRunner(*tc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to create runner")
|
log.Error().Err(err).Msg("failed to create runner")
|
||||||
os.Exit(code.GetErrorCode(err))
|
os.Exit(code.GetErrorCode(err))
|
||||||
}
|
}
|
||||||
caseRunner.parsedConfig.Parameters = caseRunner.parametersIterator.outParameters()
|
caseRunner.Config.Parameters = caseRunner.parametersIterator.outParameters()
|
||||||
parsedTestCases = append(parsedTestCases, &TCase{
|
parsedTestCases = append(parsedTestCases, &TestCase{
|
||||||
Config: caseRunner.parsedConfig,
|
Config: caseRunner.Config,
|
||||||
TestSteps: caseRunner.testCase.ToTCase().TestSteps,
|
TestSteps: caseRunner.TestSteps,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return parsedTestCases
|
return parsedTestCases
|
||||||
@@ -155,8 +154,7 @@ func (b *HRPBoomer) TestCasesToBytes(testcases ...ITestCase) []byte {
|
|||||||
log.Error().Err(err).Msg("failed to load testcases")
|
log.Error().Err(err).Msg("failed to load testcases")
|
||||||
os.Exit(code.GetErrorCode(err))
|
os.Exit(code.GetErrorCode(err))
|
||||||
}
|
}
|
||||||
tcs := b.ParseTestCases(testCases)
|
testCasesBytes, err := json.Marshal(testCases)
|
||||||
testCasesBytes, err := json.Marshal(tcs)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to marshal testcases")
|
log.Error().Err(err).Msg("failed to marshal testcases")
|
||||||
return nil
|
return nil
|
||||||
@@ -164,8 +162,8 @@ func (b *HRPBoomer) TestCasesToBytes(testcases ...ITestCase) []byte {
|
|||||||
return testCasesBytes
|
return testCasesBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *HRPBoomer) BytesToTCases(testCasesBytes []byte) []*TCase {
|
func (b *HRPBoomer) BytesToTCases(testCasesBytes []byte) []*TestCase {
|
||||||
var testcase []*TCase
|
var testcase []*TestCase
|
||||||
err := json.Unmarshal(testCasesBytes, &testcase)
|
err := json.Unmarshal(testCasesBytes, &testcase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to unmarshal testcases")
|
log.Error().Err(err).Msg("failed to unmarshal testcases")
|
||||||
@@ -177,10 +175,10 @@ func (b *HRPBoomer) Quit() {
|
|||||||
b.Boomer.Quit()
|
b.Boomer.Quit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *HRPBoomer) parseTCases(testCases []*TCase) (testcases []ITestCase) {
|
func (b *HRPBoomer) parseTCases(testCases []*TestCase) (testcases []ITestCase) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
// create temp dir to save testcase
|
// create temp dir to save testcase
|
||||||
tempDir, err := ioutil.TempDir("", "hrp_testcases")
|
tempDir, err := os.MkdirTemp("", "hrp_testcases")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to create hrp testcases directory")
|
log.Error().Err(err).Msg("failed to create hrp testcases directory")
|
||||||
return
|
return
|
||||||
@@ -215,13 +213,7 @@ func (b *HRPBoomer) parseTCases(testCases []*TCase) (testcases []ITestCase) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tesecase, err := tc.toTestCase()
|
testcases = append(testcases, tc)
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("failed to load testcases")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
testcases = append(testcases, tesecase)
|
|
||||||
}
|
}
|
||||||
return testcases
|
return testcases
|
||||||
}
|
}
|
||||||
@@ -313,7 +305,7 @@ func (b *HRPBoomer) PollTestCases(ctx context.Context) {
|
|||||||
func (b *HRPBoomer) convertBoomerTask(testcase *TestCase, rendezvousList []*Rendezvous) *boomer.Task {
|
func (b *HRPBoomer) convertBoomerTask(testcase *TestCase, rendezvousList []*Rendezvous) *boomer.Task {
|
||||||
// init case runner for testcase
|
// init case runner for testcase
|
||||||
// this runner is shared by multiple session runners
|
// this runner is shared by multiple session runners
|
||||||
caseRunner, err := b.hrpRunner.NewCaseRunner(testcase)
|
caseRunner, err := b.hrpRunner.NewCaseRunner(*testcase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to create runner")
|
log.Error().Err(err).Msg("failed to create runner")
|
||||||
os.Exit(code.GetErrorCode(err))
|
os.Exit(code.GetErrorCode(err))
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp"
|
"github.com/httprunner/httprunner/v4/hrp"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/pkg/boomer"
|
"github.com/httprunner/httprunner/v4/hrp/pkg/boomer"
|
||||||
)
|
)
|
||||||
@@ -50,7 +49,7 @@ var boomCmd = &cobra.Command{
|
|||||||
|
|
||||||
// if set profile, the priority is higher than the other commands
|
// if set profile, the priority is higher than the other commands
|
||||||
if boomArgs.profile != "" {
|
if boomArgs.profile != "" {
|
||||||
err := builtin.LoadFile(boomArgs.profile, &boomArgs.Profile)
|
err := hrp.LoadFileObject(boomArgs.profile, &boomArgs.Profile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to load profile")
|
log.Error().Err(err).Msg("failed to load profile")
|
||||||
return err
|
return err
|
||||||
@@ -156,7 +155,7 @@ func init() {
|
|||||||
func makeHRPBoomer() (*hrp.HRPBoomer, error) {
|
func makeHRPBoomer() (*hrp.HRPBoomer, error) {
|
||||||
// if set profile, the priority is higher than the other commands
|
// if set profile, the priority is higher than the other commands
|
||||||
if boomArgs.profile != "" {
|
if boomArgs.profile != "" {
|
||||||
err := builtin.LoadFile(boomArgs.profile, &boomArgs)
|
err := hrp.LoadFileObject(boomArgs.profile, &boomArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to load profile")
|
log.Error().Err(err).Msg("failed to load profile")
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user