From 488366572691cd7796c24da09a07ff7b5fe2e75b Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Tue, 20 Aug 2024 17:04:17 +0800 Subject: [PATCH] fix: boomer --- hrp/boomer.go | 36 ++++++++++++++---------------------- hrp/cmd/boom.go | 5 ++--- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/hrp/boomer.go b/hrp/boomer.go index ba24a55e..e53ed7b4 100644 --- a/hrp/boomer.go +++ b/hrp/boomer.go @@ -2,7 +2,6 @@ package hrp import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -131,18 +130,18 @@ func (b *HRPBoomer) ConvertTestCasesToBoomerTasks(testcases ...ITestCase) (taskS return taskSlice } -func (b *HRPBoomer) ParseTestCases(testCases []*TestCase) []*TCase { - var parsedTestCases []*TCase +func (b *HRPBoomer) ParseTestCases(testCases []*TestCase) []*TestCase { + var parsedTestCases []*TestCase for _, tc := range testCases { - caseRunner, err := b.hrpRunner.NewCaseRunner(tc) + caseRunner, err := b.hrpRunner.NewCaseRunner(*tc) if err != nil { log.Error().Err(err).Msg("failed to create runner") os.Exit(code.GetErrorCode(err)) } - caseRunner.parsedConfig.Parameters = caseRunner.parametersIterator.outParameters() - parsedTestCases = append(parsedTestCases, &TCase{ - Config: caseRunner.parsedConfig, - TestSteps: caseRunner.testCase.ToTCase().TestSteps, + caseRunner.Config.Parameters = caseRunner.parametersIterator.outParameters() + parsedTestCases = append(parsedTestCases, &TestCase{ + Config: caseRunner.Config, + TestSteps: caseRunner.TestSteps, }) } return parsedTestCases @@ -155,8 +154,7 @@ func (b *HRPBoomer) TestCasesToBytes(testcases ...ITestCase) []byte { log.Error().Err(err).Msg("failed to load testcases") os.Exit(code.GetErrorCode(err)) } - tcs := b.ParseTestCases(testCases) - testCasesBytes, err := json.Marshal(tcs) + testCasesBytes, err := json.Marshal(testCases) if err != nil { log.Error().Err(err).Msg("failed to marshal testcases") return nil @@ -164,8 +162,8 @@ func (b *HRPBoomer) TestCasesToBytes(testcases ...ITestCase) []byte { return testCasesBytes } -func (b *HRPBoomer) BytesToTCases(testCasesBytes []byte) []*TCase { - var testcase []*TCase +func (b *HRPBoomer) BytesToTCases(testCasesBytes []byte) []*TestCase { + var testcase []*TestCase err := json.Unmarshal(testCasesBytes, &testcase) if err != nil { log.Error().Err(err).Msg("failed to unmarshal testcases") @@ -177,10 +175,10 @@ func (b *HRPBoomer) Quit() { b.Boomer.Quit() } -func (b *HRPBoomer) parseTCases(testCases []*TCase) (testcases []ITestCase) { +func (b *HRPBoomer) parseTCases(testCases []*TestCase) (testcases []ITestCase) { for _, tc := range testCases { // create temp dir to save testcase - tempDir, err := ioutil.TempDir("", "hrp_testcases") + tempDir, err := os.MkdirTemp("", "hrp_testcases") if err != nil { log.Error().Err(err).Msg("failed to create hrp testcases directory") return @@ -215,13 +213,7 @@ func (b *HRPBoomer) parseTCases(testCases []*TCase) (testcases []ITestCase) { return } - tesecase, err := tc.toTestCase() - if err != nil { - log.Error().Err(err).Msg("failed to load testcases") - return - } - - testcases = append(testcases, tesecase) + testcases = append(testcases, tc) } return testcases } @@ -313,7 +305,7 @@ func (b *HRPBoomer) PollTestCases(ctx context.Context) { func (b *HRPBoomer) convertBoomerTask(testcase *TestCase, rendezvousList []*Rendezvous) *boomer.Task { // init case runner for testcase // this runner is shared by multiple session runners - caseRunner, err := b.hrpRunner.NewCaseRunner(testcase) + caseRunner, err := b.hrpRunner.NewCaseRunner(*testcase) if err != nil { log.Error().Err(err).Msg("failed to create runner") os.Exit(code.GetErrorCode(err)) diff --git a/hrp/cmd/boom.go b/hrp/cmd/boom.go index 6ef66506..4b159d2b 100644 --- a/hrp/cmd/boom.go +++ b/hrp/cmd/boom.go @@ -10,7 +10,6 @@ import ( "golang.org/x/net/context" "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/pkg/boomer" ) @@ -50,7 +49,7 @@ var boomCmd = &cobra.Command{ // if set profile, the priority is higher than the other commands if boomArgs.profile != "" { - err := builtin.LoadFile(boomArgs.profile, &boomArgs.Profile) + err := hrp.LoadFileObject(boomArgs.profile, &boomArgs.Profile) if err != nil { log.Error().Err(err).Msg("failed to load profile") return err @@ -156,7 +155,7 @@ func init() { func makeHRPBoomer() (*hrp.HRPBoomer, error) { // if set profile, the priority is higher than the other commands if boomArgs.profile != "" { - err := builtin.LoadFile(boomArgs.profile, &boomArgs) + err := hrp.LoadFileObject(boomArgs.profile, &boomArgs) if err != nil { log.Error().Err(err).Msg("failed to load profile") return nil, err