fix: unittests for plugin

This commit is contained in:
debugtalk
2022-01-18 17:18:16 +08:00
parent 6874a2428c
commit 9db54544d9
11 changed files with 125 additions and 41 deletions

View File

@@ -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)