mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-25 18:30:04 +08:00
fix: unittests for plugin
This commit is contained in:
@@ -2,8 +2,12 @@ package scaffold
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/hrp"
|
||||
)
|
||||
|
||||
@@ -12,6 +16,21 @@ var (
|
||||
demoTestCaseYAMLPath = "../../examples/demo.yaml"
|
||||
)
|
||||
|
||||
func buildHashicorpPlugin() {
|
||||
log.Info().Msg("[init] build hashicorp go plugin")
|
||||
cmd := exec.Command("go", "build",
|
||||
"-o", "../../examples/debugtalk.bin",
|
||||
"../../examples/plugin/hashicorp.go", "../../examples/plugin/debugtalk.go")
|
||||
if err := cmd.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func removeHashicorpPlugin() {
|
||||
log.Info().Msg("[teardown] remove hashicorp plugin")
|
||||
os.Remove("../../examples/debugtalk.bin")
|
||||
}
|
||||
|
||||
func TestGenDemoTestCase(t *testing.T) {
|
||||
tCase, _ := demoTestCase.ToTCase()
|
||||
err := tCase.Dump2JSON(demoTestCaseJSONPath)
|
||||
@@ -25,6 +44,9 @@ func TestGenDemoTestCase(t *testing.T) {
|
||||
}
|
||||
|
||||
func Example_demo() {
|
||||
buildHashicorpPlugin()
|
||||
defer removeHashicorpPlugin()
|
||||
|
||||
demoTestCase.Config.ToStruct().Path = "../../examples/debugtalk.bin"
|
||||
err := hrp.NewRunner(nil).Run(demoTestCase) // hrp.Run(demoTestCase)
|
||||
fmt.Println(err)
|
||||
@@ -33,6 +55,9 @@ func Example_demo() {
|
||||
}
|
||||
|
||||
func Example_jsonDemo() {
|
||||
buildHashicorpPlugin()
|
||||
defer removeHashicorpPlugin()
|
||||
|
||||
testCase := &hrp.TestCasePath{Path: demoTestCaseJSONPath}
|
||||
err := hrp.NewRunner(nil).Run(testCase) // hrp.Run(testCase)
|
||||
fmt.Println(err)
|
||||
@@ -41,6 +66,9 @@ func Example_jsonDemo() {
|
||||
}
|
||||
|
||||
func Example_yamlDemo() {
|
||||
buildHashicorpPlugin()
|
||||
defer removeHashicorpPlugin()
|
||||
|
||||
testCase := &hrp.TestCasePath{Path: demoTestCaseYAMLPath}
|
||||
err := hrp.NewRunner(nil).Run(testCase) // hrp.Run(testCase)
|
||||
fmt.Println(err)
|
||||
|
||||
Reference in New Issue
Block a user