mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 09:49:33 +08:00
feat: support v3 format debugtalk.py when executing hrp run/boom
This commit is contained in:
@@ -8,14 +8,22 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/build"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/scaffold"
|
||||
)
|
||||
|
||||
func buildHashicorpGoPluginWithNoFungo() {
|
||||
log.Info().Msg("[init] build hashicorp go plugin")
|
||||
err := build.Run(templatesDir+"noplugin/debugtalk.go", templatesDir+"debugtalk.bin")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("build hashicorp go plugin failed")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func buildHashicorpGoPlugin() {
|
||||
log.Info().Msg("[init] build hashicorp go plugin")
|
||||
err := builtin.ExecCommand("go", "build",
|
||||
"-o", templatesDir+"debugtalk.bin", templatesDir+"plugin/debugtalk.go")
|
||||
err := build.Run(templatesDir+"noplugin/debugtalk.go", templatesDir+"debugtalk.bin")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("build hashicorp go plugin failed")
|
||||
os.Exit(1)
|
||||
@@ -30,7 +38,7 @@ func removeHashicorpGoPlugin() {
|
||||
func buildHashicorpPyPlugin() {
|
||||
log.Info().Msg("[init] prepare hashicorp python plugin")
|
||||
pluginFile := templatesDir + "debugtalk.py"
|
||||
err := scaffold.CopyFile("templates/plugin/debugtalk.py", pluginFile)
|
||||
err := scaffold.CopyFile("templates/noplugin/debugtalk.py", pluginFile)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("build hashicorp python plugin failed")
|
||||
os.Exit(1)
|
||||
@@ -39,24 +47,14 @@ func buildHashicorpPyPlugin() {
|
||||
|
||||
func removeHashicorpPyPlugin() {
|
||||
log.Info().Msg("[teardown] remove hashicorp python plugin")
|
||||
os.Remove(templatesDir + "debugtalk.py")
|
||||
// on v4.1^, running case will generate debugtalk_gen.py used by python plugin
|
||||
os.Remove(templatesDir + "debugtalk_gen.py")
|
||||
}
|
||||
|
||||
func TestRunCaseWithGoPlugin(t *testing.T) {
|
||||
buildHashicorpGoPlugin()
|
||||
defer removeHashicorpGoPlugin()
|
||||
|
||||
assertRunTestCases(t)
|
||||
}
|
||||
|
||||
func TestRunCaseWithPythonPlugin(t *testing.T) {
|
||||
buildHashicorpPyPlugin()
|
||||
defer removeHashicorpPyPlugin()
|
||||
|
||||
assertRunTestCases(t)
|
||||
}
|
||||
|
||||
func assertRunTestCases(t *testing.T) {
|
||||
testcase1 := &TestCase{
|
||||
Config: NewConfig("TestCase1").
|
||||
SetBaseURL("http://httpbin.org"),
|
||||
@@ -83,7 +81,7 @@ func assertRunTestCases(t *testing.T) {
|
||||
},
|
||||
},
|
||||
),
|
||||
NewStep("testcase1-step4").CallRefCase(&demoTestCaseWithPluginJSONPath),
|
||||
NewStep("testcase1-step4").CallRefCase(&demoTestCaseWithGoPluginJSONPath),
|
||||
},
|
||||
}
|
||||
testcase2 := &TestCase{
|
||||
@@ -98,6 +96,18 @@ func assertRunTestCases(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunCaseWithPythonPlugin(t *testing.T) {
|
||||
buildHashicorpPyPlugin()
|
||||
defer removeHashicorpPyPlugin()
|
||||
|
||||
r := NewRunner(t)
|
||||
r.SetPluginLogOn()
|
||||
err := r.Run(&demoTestCaseWithPluginJSONPath)
|
||||
if err != nil {
|
||||
t.Fatalf("run testcase error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunCaseWithThinkTime(t *testing.T) {
|
||||
buildHashicorpGoPlugin()
|
||||
defer removeHashicorpGoPlugin()
|
||||
@@ -160,15 +170,15 @@ func TestRunCaseWithPluginJSON(t *testing.T) {
|
||||
buildHashicorpGoPlugin()
|
||||
defer removeHashicorpGoPlugin()
|
||||
|
||||
err := NewRunner(nil).Run(&demoTestCaseWithPluginJSONPath) // hrp.Run(testCase)
|
||||
err := NewRunner(nil).Run(&demoTestCaseWithGoPluginJSONPath) // hrp.Run(testCase)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunCaseWithPluginYAML(t *testing.T) {
|
||||
buildHashicorpGoPlugin()
|
||||
defer removeHashicorpGoPlugin()
|
||||
buildHashicorpPyPlugin()
|
||||
defer removeHashicorpPyPlugin()
|
||||
|
||||
err := NewRunner(nil).Run(&demoTestCaseWithPluginYAMLPath) // hrp.Run(testCase)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user