mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 03:30:01 +08:00
refactor: relocate build plugin
This commit is contained in:
+19
-15
@@ -1,20 +1,18 @@
|
||||
package hrp
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/build"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/scaffold"
|
||||
)
|
||||
|
||||
func buildHashicorpGoPlugin() {
|
||||
log.Info().Msg("[init] build hashicorp go plugin")
|
||||
err := build.Run(templatesDir+"plugin/debugtalk.go", templatesDir+"debugtalk.bin")
|
||||
err := BuildPlugin(tmpl("plugin/debugtalk.go"), tmpl("debugtalk.bin"))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("build hashicorp go plugin failed")
|
||||
os.Exit(1)
|
||||
@@ -23,15 +21,15 @@ func buildHashicorpGoPlugin() {
|
||||
|
||||
func removeHashicorpGoPlugin() {
|
||||
log.Info().Msg("[teardown] remove hashicorp go plugin")
|
||||
os.Remove(templatesDir + "debugtalk.bin")
|
||||
os.Remove(tmpl("debugtalk.bin"))
|
||||
}
|
||||
|
||||
func buildHashicorpPyPlugin() {
|
||||
log.Info().Msg("[init] prepare hashicorp python plugin")
|
||||
pluginFile := templatesDir + "debugtalk.py"
|
||||
err := scaffold.CopyFile("templates/plugin/debugtalk.py", pluginFile)
|
||||
src, _ := ioutil.ReadFile(tmpl("plugin/debugtalk.py"))
|
||||
err := ioutil.WriteFile(tmpl("debugtalk.py"), src, 0o644)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("build hashicorp python plugin failed")
|
||||
log.Error().Err(err).Msg("copy hashicorp python plugin failed")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -39,7 +37,8 @@ func buildHashicorpPyPlugin() {
|
||||
func removeHashicorpPyPlugin() {
|
||||
log.Info().Msg("[teardown] remove hashicorp python plugin")
|
||||
// on v4.1^, running case will generate .debugtalk_gen.py used by python plugin
|
||||
os.Remove(templatesDir + hashicorpPyPluginFile)
|
||||
os.Remove(tmpl(PluginPySourceFile))
|
||||
os.Remove(tmpl(PluginPySourceGenFile))
|
||||
}
|
||||
|
||||
func TestRunCaseWithGoPlugin(t *testing.T) {
|
||||
@@ -57,6 +56,7 @@ func TestRunCaseWithPythonPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
func assertRunTestCases(t *testing.T) {
|
||||
refCase := TestCasePath(demoTestCaseWithPluginJSONPath)
|
||||
testcase1 := &TestCase{
|
||||
Config: NewConfig("TestCase1").
|
||||
SetBaseURL("http://httpbin.org"),
|
||||
@@ -83,7 +83,7 @@ func assertRunTestCases(t *testing.T) {
|
||||
},
|
||||
},
|
||||
),
|
||||
NewStep("testcase1-step4").CallRefCase(&demoTestCaseWithPluginJSONPath),
|
||||
NewStep("testcase1-step4").CallRefCase(&refCase),
|
||||
},
|
||||
}
|
||||
testcase2 := &TestCase{
|
||||
@@ -160,7 +160,8 @@ func TestRunCaseWithPluginJSON(t *testing.T) {
|
||||
buildHashicorpGoPlugin()
|
||||
defer removeHashicorpGoPlugin()
|
||||
|
||||
err := NewRunner(nil).Run(&demoTestCaseWithPluginJSONPath) // hrp.Run(testCase)
|
||||
testCase := TestCasePath(demoTestCaseWithPluginJSONPath)
|
||||
err := NewRunner(nil).Run(&testCase) // hrp.Run(testCase)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
@@ -170,7 +171,8 @@ func TestRunCaseWithPluginYAML(t *testing.T) {
|
||||
buildHashicorpGoPlugin()
|
||||
defer removeHashicorpGoPlugin()
|
||||
|
||||
err := NewRunner(nil).Run(&demoTestCaseWithPluginYAMLPath) // hrp.Run(testCase)
|
||||
testCase := TestCasePath(demoTestCaseWithPluginYAMLPath)
|
||||
err := NewRunner(nil).Run(&testCase) // hrp.Run(testCase)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
@@ -180,16 +182,18 @@ func TestRunCaseWithRefAPI(t *testing.T) {
|
||||
buildHashicorpGoPlugin()
|
||||
defer removeHashicorpGoPlugin()
|
||||
|
||||
err := NewRunner(nil).Run(&demoTestCaseWithRefAPIPath)
|
||||
testCase := TestCasePath(demoTestCaseWithRefAPIPath)
|
||||
err := NewRunner(nil).Run(&testCase)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
refAPI := APIPath(demoAPIGETPath)
|
||||
testcase := &TestCase{
|
||||
Config: NewConfig("TestCase").
|
||||
SetBaseURL("https://postman-echo.com"),
|
||||
TestSteps: []IStep{
|
||||
NewStep("run referenced api").CallRefAPI(&demoAPIGETPath),
|
||||
NewStep("run referenced api").CallRefAPI(&refAPI),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -222,7 +226,7 @@ func TestLoadTestCases(t *testing.T) {
|
||||
}
|
||||
|
||||
// load test cases from single file path
|
||||
tc = demoTestCaseWithPluginJSONPath
|
||||
tc = TestCasePath(demoTestCaseWithPluginJSONPath)
|
||||
testCases, err = LoadTestCases(&tc)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Fatal()
|
||||
|
||||
Reference in New Issue
Block a user