From 67c0cb86409433c15327bd19fdb10eb323271fa9 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Fri, 20 May 2022 16:53:09 +0800 Subject: [PATCH 1/6] feat: add build command for plugin --- hrp/cmd/build.go | 26 ++ .../build/examples/debugtalk_no_fungo.go | 40 +++ .../build/examples/debugtalk_no_funppy.py | 53 +++ hrp/internal/build/main.go | 304 ++++++++++++++++++ hrp/internal/build/main_test.go | 44 +++ .../build/templates/debugtalkGoTemplate | 17 + .../build/templates/debugtalkPythonTemplate | 15 + 7 files changed, 499 insertions(+) create mode 100644 hrp/cmd/build.go create mode 100644 hrp/internal/build/examples/debugtalk_no_fungo.go create mode 100644 hrp/internal/build/examples/debugtalk_no_funppy.py create mode 100644 hrp/internal/build/main.go create mode 100644 hrp/internal/build/main_test.go create mode 100644 hrp/internal/build/templates/debugtalkGoTemplate create mode 100644 hrp/internal/build/templates/debugtalkPythonTemplate diff --git a/hrp/cmd/build.go b/hrp/cmd/build.go new file mode 100644 index 00000000..093132ea --- /dev/null +++ b/hrp/cmd/build.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/spf13/cobra" + + "github.com/httprunner/httprunner/v4/hrp/internal/build" +) + +var buildCmd = &cobra.Command{ + Use: "build $path ...", + Short: "build plugin for testing", + Long: `build python/go plugin for testing`, + Example: ` $ hrp build plugin/debugtalk.go + $ hrp build plugin/debugtalk.py`, + Args: cobra.MinimumNArgs(1), + PreRun: func(cmd *cobra.Command, args []string) { + setLogLevel(logLevel) + }, + RunE: func(cmd *cobra.Command, args []string) error { + return build.Run(args) + }, +} + +func init() { + rootCmd.AddCommand(buildCmd) +} diff --git a/hrp/internal/build/examples/debugtalk_no_fungo.go b/hrp/internal/build/examples/debugtalk_no_fungo.go new file mode 100644 index 00000000..9a57a294 --- /dev/null +++ b/hrp/internal/build/examples/debugtalk_no_fungo.go @@ -0,0 +1,40 @@ +package examples + +import ( + "fmt" +) + +func SumTwoInt(a, b int) int { + return a + b +} + +func SumInts(args ...int) int { + var sum int + for _, arg := range args { + sum += arg + } + return sum +} + +func Sum(args ...interface{}) (interface{}, error) { + var sum float64 + for _, arg := range args { + switch v := arg.(type) { + case int: + sum += float64(v) + case float64: + sum += v + default: + return nil, fmt.Errorf("unexpected type: %T", arg) + } + } + return sum, nil +} + +func SetupHookExample(args string) string { + return fmt.Sprintf("step name: %v, setup...", args) +} + +func TeardownHookExample(args string) string { + return fmt.Sprintf("step name: %v, teardown...", args) +} diff --git a/hrp/internal/build/examples/debugtalk_no_funppy.py b/hrp/internal/build/examples/debugtalk_no_funppy.py new file mode 100644 index 00000000..370206d6 --- /dev/null +++ b/hrp/internal/build/examples/debugtalk_no_funppy.py @@ -0,0 +1,53 @@ +import logging +import time +from typing import List + + +def sleep(n_secs): + time.sleep(n_secs) + + +def sum(*args): + result = 0 + for arg in args: + result += arg + return result + + +def sum_ints(*args: List[int]) -> int: + result = 0 + for arg in args: + result += arg + return result + + +def sum_two_int(a: int, b: int) -> int: + return a + b + + +def sum_two_string(a: str, b: str) -> str: + return a + b + + +def sum_strings(*args: List[str]) -> str: + result = "" + for arg in args: + result += arg + return result + + +def concatenate(*args: List[str]) -> str: + result = "" + for arg in args: + result += str(arg) + return result + + +def setup_hook_example(name): + logging.warning("setup_hook_example") + return f"setup_hook_example: {name}" + + +def teardown_hook_example(name): + logging.warning("teardown_hook_example") + return f"teardown_hook_example: {name}" diff --git a/hrp/internal/build/main.go b/hrp/internal/build/main.go new file mode 100644 index 00000000..747ed181 --- /dev/null +++ b/hrp/internal/build/main.go @@ -0,0 +1,304 @@ +package build + +import ( + "bufio" + _ "embed" + "fmt" + "io" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "regexp" + "strings" + "text/template" + + "github.com/httprunner/funplugin/shared" + "github.com/httprunner/httprunner/v4/hrp/internal/builtin" + "github.com/pkg/errors" + "github.com/rs/zerolog/log" +) + +const ( + funppy = `import funppy` + fungo = `"github.com/httprunner/funplugin/fungo"` + regexPythonFunctionName = `def ([a-zA-Z_]\w*)\(.*\)` + regexGoImport = `import\s*\(\n([\s\S]*)\n\)` + regexGoFunctionName = `func ([a-zA-Z_]\w*)\(.*\)` + regexGoFunctionContent = `func [\s\S]*?\n}\n` +) + +//go:embed templates/debugtalkPythonTemplate +var pyTemplate string + +//go:embed templates/debugtalkGoTemplate +var goTemplate string + +type TemplateContent struct { + Fun string // funplugin package + Regexps *Regexps // match import/function + Imports []string // python/go import + FromImports []string // python from...import... + Functions []string // python/go function + FunctionNames []string // function name set by user + FunctionSnakeNames []string // function snake name converts by function name for registering plugin +} + +type Regexps struct { + Import *regexp.Regexp + FunctionName *regexp.Regexp + FunctionContent *regexp.Regexp // including function define and body +} + +func (t *TemplateContent) parseGoContent(path string) error { + log.Info().Msg(fmt.Sprintf("start to parse %v", path)) + + content, err := os.ReadFile(path) + if err != nil { + log.Error().Err(err).Msg("failed to read file") + return err + } + originalContent := string(content) + + // parse imports + importSlice := t.Regexps.Import.FindAllStringSubmatch(originalContent, -1) + if len(importSlice) != 0 { + imports := strings.Replace(importSlice[0][1], "\t", "", -1) + for _, elem := range strings.Split(imports, "\n") { + t.Imports = append(t.Imports, elem) + } + } else { + if strings.Contains(originalContent, "\nimport ") { + return errors.New(`import style error, expected import ( ... )`) + } + } + // import fungo package + if !builtin.Contains(t.Imports, fungo) { + t.Imports = append(t.Imports, t.Fun) + } + + // parse function name + functionNameSlice := t.Regexps.FunctionName.FindAllStringSubmatch(originalContent, -1) + for _, elem := range functionNameSlice { + name := strings.Trim(elem[1], " ") + if name == "main" { + continue + } + t.FunctionNames = append(t.FunctionNames, name) + t.FunctionSnakeNames = append(t.FunctionSnakeNames, convertSnakeName(name)) + } + + // parse function content + functionContentSlice := t.Regexps.FunctionContent.FindAllStringSubmatch(originalContent, -1) + for _, f := range functionContentSlice { + if strings.Contains(f[0], "func main") { + continue + } + t.Functions = append(t.Functions, strings.Trim(f[0], "\n")) + } + return nil +} + +func (t *TemplateContent) parsePyContent(path string) error { + file, err := os.Open(path) + if err != nil { + fmt.Printf("Error: %s\n", err) + return err + } + defer file.Close() + + r := bufio.NewReader(file) + + // record content excluding import and main + content := "" + + // parse python content line by line + for { + l, _, err := r.ReadLine() + if err == io.EOF { + break + } + line := string(l) + + if strings.HasPrefix(line, "import") { + t.Imports = append(t.Imports, strings.Trim(line, " ")) + } else if strings.HasPrefix(line, "from") { + t.FromImports = append(t.FromImports, strings.Trim(line, " ")) + } else { + // no parse content at under of `if __name__ == "__main__"` + if strings.HasPrefix(line, "if __name__") { + break + } + if strings.HasPrefix(line, "def") { + functionNameSlice := t.Regexps.FunctionName.FindAllStringSubmatch(line, -1) + if len(functionNameSlice) == 0 { + continue + } + t.FunctionNames = append(t.FunctionNames, functionNameSlice[0][1]) + t.FunctionSnakeNames = append(t.FunctionSnakeNames, convertSnakeName(functionNameSlice[0][1])) + } + content += line + "\n" + } + } + // function content + t.Functions = append(t.Functions, strings.Trim(content, "\n")) + + // import funppy + if !builtin.Contains(t.Imports, t.Fun) { + t.Imports = append(t.Imports, t.Fun) + } + return nil +} + +func (t *TemplateContent) genDebugTalk(path string, templ string) error { + file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o666) + if err != nil { + log.Error().Err(err).Msg("open file failed") + return err + } + defer file.Close() + writer := bufio.NewWriter(file) + tmpl := template.Must(template.New("debugtalk").Parse(templ)) + err = tmpl.Execute(writer, t) + if err != nil { + log.Error().Err(err).Msg("execute applies a parsed template to the specified data object failed") + return err + } + err = writer.Flush() + if err == nil { + log.Info().Str("path", path).Msg("generate debugtalk success") + } else { + log.Error().Str("path", path).Msg("generate debugtalk failed") + } + return err +} + +// buildGo builds debugtalk.go to debugtalk.bin +func buildGo(path string) error { + templateContent := &TemplateContent{ + Fun: fungo, + Regexps: &Regexps{ + Import: regexp.MustCompile(regexGoImport), + FunctionName: regexp.MustCompile(regexGoFunctionName), + FunctionContent: regexp.MustCompile(regexGoFunctionContent), + }, + } + dir, _ := filepath.Split(path) + + // create temp dir for building + tempDir, err := ioutil.TempDir("", "hrp_build") + if err != nil { + return err + } + + // check go sdk in tempDir + if err := builtin.ExecCommandInDir(exec.Command("go", "version"), tempDir); err != nil { + return errors.Wrap(err, "go sdk not installed") + } + + // create pluginDir + pluginDir := filepath.Join(tempDir, "plugin") + if err := builtin.CreateFolder(pluginDir); err != nil { + return err + } + // parse debugtalk.go in pluginDir + err = templateContent.parseGoContent(path) + if err != nil { + return err + } + // generate debugtalk.go in pluginDir + err = templateContent.genDebugTalk(filepath.Join(pluginDir, "debugtalk.go"), goTemplate) + if err != nil { + return err + } + + // create go mod + if err := builtin.ExecCommandInDir(exec.Command("go", "mod", "init", "plugin"), pluginDir); err != nil { + return err + } + + // download plugin dependency + // funplugin version should be locked + funplugin := fmt.Sprintf("github.com/httprunner/funplugin@%s", shared.Version) + if err := builtin.ExecCommandInDir(exec.Command("go", "get", funplugin), pluginDir); err != nil { + return err + } + + outputPath, err := filepath.Abs(filepath.Join(dir, "../debugtalk.bin")) + if err != nil { + return err + } + + // build plugin debugtalk.bin + if err := builtin.ExecCommandInDir(exec.Command("go", "build", "-o", outputPath, "debugtalk.go"), pluginDir); err != nil { + return err + } + log.Info().Msg(fmt.Sprintf("build %s to %s successfully", path, outputPath)) + return nil +} + +// buildPy completes funppy information in debugtalk.py +func buildPy(path string) error { + templateContent := &TemplateContent{ + Fun: funppy, + Regexps: &Regexps{ + FunctionName: regexp.MustCompile(regexPythonFunctionName), + }, + } + err := templateContent.parsePyContent(path) + if err != nil { + return err + } + + // generate debugtalk.py + dir, _ := filepath.Split(path) + err = templateContent.genDebugTalk(filepath.Join(dir, "../debugtalk.py"), pyTemplate) + if err != nil { + return err + } + + // ensure funppy in .env + _, err = builtin.EnsurePython3Venv("funppy") + if err != nil { + return err + } + + return nil +} + +func Run(args []string) (err error) { + for _, arg := range args { + ext := filepath.Ext(arg) + switch ext { + case ".py": + err = buildPy(arg) + case ".go": + err = buildGo(arg) + default: + return errors.New("type error, expected .py or .go") + } + if err != nil { + log.Error().Err(err).Msg(fmt.Sprintf("failed to build %s", arg)) + os.Exit(1) + } + } + return nil +} + +// convertSnakeName converts name to snake name +func convertSnakeName(originalName string) string { + snakeName := make([]byte, 0, len(originalName)*2) + flag := false + num := len(originalName) + for i := 0; i < num; i++ { + ch := originalName[i] + if i > 0 && ch >= 'A' && ch <= 'Z' && flag { + snakeName = append(snakeName, '_') + } + if ch != '_' { + flag = true + } + snakeName = append(snakeName, ch) + } + return strings.ToLower(string(snakeName)) +} diff --git a/hrp/internal/build/main_test.go b/hrp/internal/build/main_test.go new file mode 100644 index 00000000..ef9e769f --- /dev/null +++ b/hrp/internal/build/main_test.go @@ -0,0 +1,44 @@ +package build + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRun(t *testing.T) { + err := Run([]string{"examples/debugtalk_no_funppy.py", "examples/debugtalk_no_fungo.go"}) + if !assert.Nil(t, err) { + t.Fatal() + } +} + +func TestConvertSnakeName(t *testing.T) { + testData := []struct { + expectedValue string + originalValue string + }{ + { + expectedValue: "test_name", + originalValue: "testName", + }, + { + expectedValue: "test", + originalValue: "test", + }, + { + expectedValue: "test_name", + originalValue: "TestName", + }, + { + expectedValue: "test_name", + originalValue: "test_name", + }, + } + for _, data := range testData { + name := convertSnakeName(data.originalValue) + if !assert.Equal(t, data.expectedValue, name) { + t.Fatal() + } + } +} diff --git a/hrp/internal/build/templates/debugtalkGoTemplate b/hrp/internal/build/templates/debugtalkGoTemplate new file mode 100644 index 00000000..805d0813 --- /dev/null +++ b/hrp/internal/build/templates/debugtalkGoTemplate @@ -0,0 +1,17 @@ +package main + +import ( +{{- range $import := .Imports }} + {{ $import -}} +{{ end }} +) + +{{ range $function := .Functions }} +{{ $function }} +{{ end }} +func main() { +{{- range $idx, $name := .FunctionNames }} + fungo.Register("{{ index $.FunctionSnakeNames $idx }}", {{ $name }}) +{{- end }} + fungo.Serve() +} diff --git a/hrp/internal/build/templates/debugtalkPythonTemplate b/hrp/internal/build/templates/debugtalkPythonTemplate new file mode 100644 index 00000000..d5b209ec --- /dev/null +++ b/hrp/internal/build/templates/debugtalkPythonTemplate @@ -0,0 +1,15 @@ +{{- range $import := .Imports }} +{{- $import}} +{{ end }} +{{ range $fromImport := .FromImports }} +{{- $fromImport}} +{{ end }} +{{ range $function := .Functions }} +{{ $function }} + +{{ end }} +if __name__ == "__main__": +{{- range $mainRegSnake := .FunctionSnakeNames }} + funppy.register("{{ $mainRegSnake }}", {{ $mainRegSnake }}) +{{- end }} + funppy.serve() From 2bee7ba3c7917f3ebacef0a367665e164ae99073 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Thu, 26 May 2022 21:26:48 +0800 Subject: [PATCH 2/6] feat: add --output command in hrp build --- hrp/cmd/build.go | 8 +- .../build/examples/debugtalk_no_fungo.go | 6 ++ hrp/internal/build/main.go | 101 ++++++++---------- hrp/internal/build/main_test.go | 47 +++----- .../build/templates/debugtalkGoTemplate | 4 +- .../build/templates/debugtalkPythonTemplate | 4 +- 6 files changed, 79 insertions(+), 91 deletions(-) diff --git a/hrp/cmd/build.go b/hrp/cmd/build.go index 093132ea..da174bbc 100644 --- a/hrp/cmd/build.go +++ b/hrp/cmd/build.go @@ -12,15 +12,19 @@ var buildCmd = &cobra.Command{ Long: `build python/go plugin for testing`, Example: ` $ hrp build plugin/debugtalk.go $ hrp build plugin/debugtalk.py`, - Args: cobra.MinimumNArgs(1), + Args: cobra.ExactArgs(1), PreRun: func(cmd *cobra.Command, args []string) { setLogLevel(logLevel) }, RunE: func(cmd *cobra.Command, args []string) error { - return build.Run(args) + return build.Run(args[0], output) }, } +var output string + func init() { rootCmd.AddCommand(buildCmd) + + buildCmd.Flags().StringVarP(&output, "output", "o", "", "funplugin product output path, default: cwd") } diff --git a/hrp/internal/build/examples/debugtalk_no_fungo.go b/hrp/internal/build/examples/debugtalk_no_fungo.go index 9a57a294..12d5ce57 100644 --- a/hrp/internal/build/examples/debugtalk_no_fungo.go +++ b/hrp/internal/build/examples/debugtalk_no_fungo.go @@ -4,6 +4,8 @@ import ( "fmt" ) +import "os" + func SumTwoInt(a, b int) int { return a + b } @@ -38,3 +40,7 @@ func SetupHookExample(args string) string { func TeardownHookExample(args string) string { return fmt.Sprintf("step name: %v, teardown...", args) } + +func init() { + _, _ = os.Getwd() +} diff --git a/hrp/internal/build/main.go b/hrp/internal/build/main.go index 747ed181..afadf8aa 100644 --- a/hrp/internal/build/main.go +++ b/hrp/internal/build/main.go @@ -23,8 +23,9 @@ const ( funppy = `import funppy` fungo = `"github.com/httprunner/funplugin/fungo"` regexPythonFunctionName = `def ([a-zA-Z_]\w*)\(.*\)` - regexGoImport = `import\s*\(\n([\s\S]*)\n\)` - regexGoFunctionName = `func ([a-zA-Z_]\w*)\(.*\)` + regexGoImports = `import\s*\(\n([\s\S]*)\n\)` + regexGoImport = `import\s*(\"[\s\S]*\")\n` + regexGoFunctionName = `func ([A-Z][a-zA-Z_]\w*)\(.*\)` regexGoFunctionContent = `func [\s\S]*?\n}\n` ) @@ -35,17 +36,17 @@ var pyTemplate string var goTemplate string type TemplateContent struct { - Fun string // funplugin package - Regexps *Regexps // match import/function - Imports []string // python/go import - FromImports []string // python from...import... - Functions []string // python/go function - FunctionNames []string // function name set by user - FunctionSnakeNames []string // function snake name converts by function name for registering plugin + Fun string // funplugin package + Regexps *Regexps // match import/function + Imports []string // python/go import + FromImports []string // python from...import... + Functions []string // python/go function + FunctionNames []string // function name set by user } type Regexps struct { Import *regexp.Regexp + Imports *regexp.Regexp FunctionName *regexp.Regexp FunctionContent *regexp.Regexp // including function define and body } @@ -65,11 +66,14 @@ func (t *TemplateContent) parseGoContent(path string) error { if len(importSlice) != 0 { imports := strings.Replace(importSlice[0][1], "\t", "", -1) for _, elem := range strings.Split(imports, "\n") { - t.Imports = append(t.Imports, elem) + t.Imports = append(t.Imports, strings.TrimSpace(elem)) } - } else { - if strings.Contains(originalContent, "\nimport ") { - return errors.New(`import style error, expected import ( ... )`) + } + // parse import + importSlice = t.Regexps.Imports.FindAllStringSubmatch(originalContent, -1) + if len(importSlice) != 0 { + for _, elem := range importSlice { + t.Imports = append(t.Imports, strings.TrimSpace(elem[1])) } } // import fungo package @@ -85,7 +89,6 @@ func (t *TemplateContent) parseGoContent(path string) error { continue } t.FunctionNames = append(t.FunctionNames, name) - t.FunctionSnakeNames = append(t.FunctionSnakeNames, convertSnakeName(name)) } // parse function content @@ -135,7 +138,6 @@ func (t *TemplateContent) parsePyContent(path string) error { continue } t.FunctionNames = append(t.FunctionNames, functionNameSlice[0][1]) - t.FunctionSnakeNames = append(t.FunctionSnakeNames, convertSnakeName(functionNameSlice[0][1])) } content += line + "\n" } @@ -174,16 +176,16 @@ func (t *TemplateContent) genDebugTalk(path string, templ string) error { } // buildGo builds debugtalk.go to debugtalk.bin -func buildGo(path string) error { +func buildGo(path string, output string) error { templateContent := &TemplateContent{ Fun: fungo, Regexps: &Regexps{ Import: regexp.MustCompile(regexGoImport), + Imports: regexp.MustCompile(regexGoImports), FunctionName: regexp.MustCompile(regexGoFunctionName), FunctionContent: regexp.MustCompile(regexGoFunctionContent), }, } - dir, _ := filepath.Split(path) // create temp dir for building tempDir, err := ioutil.TempDir("", "hrp_build") @@ -224,7 +226,13 @@ func buildGo(path string) error { return err } - outputPath, err := filepath.Abs(filepath.Join(dir, "../debugtalk.bin")) + if output == "" { + dir, _ := os.Getwd() + output = filepath.Join(dir, "debugtalk.bin") + } else if builtin.IsFolderPathExists(output) { + output = filepath.Join(output, "debugtalk.bin") + } + outputPath, err := filepath.Abs(output) if err != nil { return err } @@ -238,7 +246,7 @@ func buildGo(path string) error { } // buildPy completes funppy information in debugtalk.py -func buildPy(path string) error { +func buildPy(path string, output string) error { templateContent := &TemplateContent{ Fun: funppy, Regexps: &Regexps{ @@ -251,8 +259,13 @@ func buildPy(path string) error { } // generate debugtalk.py - dir, _ := filepath.Split(path) - err = templateContent.genDebugTalk(filepath.Join(dir, "../debugtalk.py"), pyTemplate) + if output == "" { + dir, _ := os.Getwd() + output = filepath.Join(dir, "debugtalk.py") + } else if builtin.IsFolderPathExists(output) { + output = filepath.Join(output, "debugtalk.py") + } + err = templateContent.genDebugTalk(output, pyTemplate) if err != nil { return err } @@ -266,39 +279,19 @@ func buildPy(path string) error { return nil } -func Run(args []string) (err error) { - for _, arg := range args { - ext := filepath.Ext(arg) - switch ext { - case ".py": - err = buildPy(arg) - case ".go": - err = buildGo(arg) - default: - return errors.New("type error, expected .py or .go") - } - if err != nil { - log.Error().Err(err).Msg(fmt.Sprintf("failed to build %s", arg)) - os.Exit(1) - } +func Run(arg string, output string) (err error) { + ext := filepath.Ext(arg) + switch ext { + case ".py": + err = buildPy(arg, output) + case ".go": + err = buildGo(arg, output) + default: + return errors.New("type error, expected .py or .go") + } + if err != nil { + log.Error().Err(err).Msg(fmt.Sprintf("failed to build %s", arg)) + os.Exit(1) } return nil } - -// convertSnakeName converts name to snake name -func convertSnakeName(originalName string) string { - snakeName := make([]byte, 0, len(originalName)*2) - flag := false - num := len(originalName) - for i := 0; i < num; i++ { - ch := originalName[i] - if i > 0 && ch >= 'A' && ch <= 'Z' && flag { - snakeName = append(snakeName, '_') - } - if ch != '_' { - flag = true - } - snakeName = append(snakeName, ch) - } - return strings.ToLower(string(snakeName)) -} diff --git a/hrp/internal/build/main_test.go b/hrp/internal/build/main_test.go index ef9e769f..8a58cfe4 100644 --- a/hrp/internal/build/main_test.go +++ b/hrp/internal/build/main_test.go @@ -7,38 +7,23 @@ import ( ) func TestRun(t *testing.T) { - err := Run([]string{"examples/debugtalk_no_funppy.py", "examples/debugtalk_no_fungo.go"}) + err := Run("examples/debugtalk_no_funppy.py", "") + if !assert.Nil(t, err) { + t.Fatal() + } + + err = Run("examples/debugtalk_no_fungo.go", "") + if !assert.Nil(t, err) { + t.Fatal() + } + + err = Run("examples/debugtalk_no_funppy.py", "./debugtalk_gen.py") + if !assert.Nil(t, err) { + t.Fatal() + } + + err = Run("examples/debugtalk_no_fungo.go", "./debugtalk_gen.bin") if !assert.Nil(t, err) { t.Fatal() } } - -func TestConvertSnakeName(t *testing.T) { - testData := []struct { - expectedValue string - originalValue string - }{ - { - expectedValue: "test_name", - originalValue: "testName", - }, - { - expectedValue: "test", - originalValue: "test", - }, - { - expectedValue: "test_name", - originalValue: "TestName", - }, - { - expectedValue: "test_name", - originalValue: "test_name", - }, - } - for _, data := range testData { - name := convertSnakeName(data.originalValue) - if !assert.Equal(t, data.expectedValue, name) { - t.Fatal() - } - } -} diff --git a/hrp/internal/build/templates/debugtalkGoTemplate b/hrp/internal/build/templates/debugtalkGoTemplate index 805d0813..d6d0a95e 100644 --- a/hrp/internal/build/templates/debugtalkGoTemplate +++ b/hrp/internal/build/templates/debugtalkGoTemplate @@ -10,8 +10,8 @@ import ( {{ $function }} {{ end }} func main() { -{{- range $idx, $name := .FunctionNames }} - fungo.Register("{{ index $.FunctionSnakeNames $idx }}", {{ $name }}) +{{- range $idx, $functionName := .FunctionNames }} + fungo.Register("{{ $functionName }}", {{ $functionName }}) {{- end }} fungo.Serve() } diff --git a/hrp/internal/build/templates/debugtalkPythonTemplate b/hrp/internal/build/templates/debugtalkPythonTemplate index d5b209ec..4da17d12 100644 --- a/hrp/internal/build/templates/debugtalkPythonTemplate +++ b/hrp/internal/build/templates/debugtalkPythonTemplate @@ -9,7 +9,7 @@ {{ end }} if __name__ == "__main__": -{{- range $mainRegSnake := .FunctionSnakeNames }} - funppy.register("{{ $mainRegSnake }}", {{ $mainRegSnake }}) +{{- range $functionName := .FunctionNames }} + funppy.register("{{ $functionName }}", {{ $functionName }}) {{- end }} funppy.serve() From 726e5666685e86363d57533ec2de884b9b8565af Mon Sep 17 00:00:00 2001 From: xucong053 Date: Thu, 26 May 2022 21:57:35 +0800 Subject: [PATCH 3/6] fix: default output debugtalk_gen.py by building debugtalk.py --- hrp/internal/build/main.go | 4 ++-- hrp/internal/build/main_test.go | 2 +- hrp/plugin.go | 15 ++++++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/hrp/internal/build/main.go b/hrp/internal/build/main.go index afadf8aa..811801ab 100644 --- a/hrp/internal/build/main.go +++ b/hrp/internal/build/main.go @@ -261,9 +261,9 @@ func buildPy(path string, output string) error { // generate debugtalk.py if output == "" { dir, _ := os.Getwd() - output = filepath.Join(dir, "debugtalk.py") + output = filepath.Join(dir, "debugtalk_gen.py") } else if builtin.IsFolderPathExists(output) { - output = filepath.Join(output, "debugtalk.py") + output = filepath.Join(output, "debugtalk_gen.py") } err = templateContent.genDebugTalk(output, pyTemplate) if err != nil { diff --git a/hrp/internal/build/main_test.go b/hrp/internal/build/main_test.go index 8a58cfe4..a169c77a 100644 --- a/hrp/internal/build/main_test.go +++ b/hrp/internal/build/main_test.go @@ -17,7 +17,7 @@ func TestRun(t *testing.T) { t.Fatal() } - err = Run("examples/debugtalk_no_funppy.py", "./debugtalk_gen.py") + err = Run("examples/debugtalk_no_funppy.py", "./debugtalk.py") if !assert.Nil(t, err) { t.Fatal() } diff --git a/hrp/plugin.go b/hrp/plugin.go index f9465a90..004fc1cb 100644 --- a/hrp/plugin.go +++ b/hrp/plugin.go @@ -14,10 +14,10 @@ import ( ) const ( - goPluginFile = "debugtalk.so" // built from go plugin - hashicorpGoPluginFile = "debugtalk.bin" // built from hashicorp go plugin - hashicorpPyPluginFile = "debugtalk.py" // used for hashicorp python plugin - projectInfoFile = "proj.json" // used for ensuring root project + goPluginFile = "debugtalk.so" // built from go plugin + hashicorpGoPluginFile = "debugtalk.bin" // built from hashicorp go plugin + hashicorpPyPluginFile = "debugtalk_gen.py" // used for hashicorp python plugin, automatically generated by HRP + debugtalkPyFile = "debugtalk.py" // write by user ) func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir string, err error) { @@ -62,7 +62,7 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir st } func locatePlugin(path string) (pluginPath string, err error) { - // priority: hashicorp plugin (debugtalk.bin > debugtalk.py) > go plugin (debugtalk.so) + // priority: hashicorp plugin (debugtalk.bin > debugtalk_gen.py > debugtalk.py) > go plugin (debugtalk.so) pluginPath, err = locateFile(path, hashicorpGoPluginFile) if err == nil { @@ -74,6 +74,11 @@ func locatePlugin(path string) (pluginPath string, err error) { return } + pluginPath, err = locateFile(path, debugtalkPyFile) + if err == nil { + return + } + pluginPath, err = locateFile(path, goPluginFile) if err == nil { return From 5c2be8d5482e1b09f39fa6369d59e033e8b286eb Mon Sep 17 00:00:00 2001 From: xucong053 Date: Fri, 27 May 2022 11:20:21 +0800 Subject: [PATCH 4/6] feat: support v3 format debugtalk.py when executing hrp run/boom --- docs/cmd/hrp.md | 1 + .../demo-with-go-plugin/plugin/debugtalk.go | 14 +- .../demo-with-go-plugin/testcases/demo.json | 8 +- .../testcases/ref_testcase.yml | 2 +- .../testcases/requests.json | 8 +- .../testcases/requests.yml | 8 +- examples/demo-with-no-fungo/.gitignore | 15 ++ examples/demo-with-no-fungo/har/.keep | 0 .../demo-with-no-fungo/plugin/debugtalk.go | 10 +- .../demo-with-no-fungo/testcases/demo.json | 176 ++++++++++++++++++ .../testcases/ref_testcase.yml | 33 ++++ .../testcases/requests.json | 138 ++++++++++++++ .../demo-with-no-fungo/testcases/requests.yml | 65 +++++++ examples/demo-with-no-funppy/.gitignore | 15 ++ .../demo-with-no-funppy/debugtalk.py | 4 + examples/demo-with-no-funppy/har/.keep | 0 .../demo-with-no-funppy/testcases/demo.json | 176 ++++++++++++++++++ .../testcases/ref_testcase.yml | 33 ++++ .../testcases/requests.json | 138 ++++++++++++++ .../testcases/requests.yml | 65 +++++++ hrp/boomer_test.go | 2 +- hrp/internal/build/main.go | 4 +- hrp/internal/build/main_test.go | 30 ++- hrp/internal/builtin/utils.go | 8 +- .../scaffold/templates/plugin/debugtalk.go | 14 +- .../testcases/demo_go_ref_testcase.yml | 33 ++++ .../templates/testcases/demo_go_requests.json | 138 ++++++++++++++ .../templates/testcases/demo_go_requests.yml | 65 +++++++ .../testcases/demo_go_with_funplugin.json | 176 ++++++++++++++++++ hrp/plugin.go | 23 ++- hrp/runner_test.go | 50 +++-- hrp/testcase_test.go | 1 + 32 files changed, 1386 insertions(+), 67 deletions(-) create mode 100644 examples/demo-with-no-fungo/.gitignore create mode 100644 examples/demo-with-no-fungo/har/.keep rename hrp/internal/build/examples/debugtalk_no_fungo.go => examples/demo-with-no-fungo/plugin/debugtalk.go (93%) create mode 100644 examples/demo-with-no-fungo/testcases/demo.json create mode 100644 examples/demo-with-no-fungo/testcases/ref_testcase.yml create mode 100644 examples/demo-with-no-fungo/testcases/requests.json create mode 100644 examples/demo-with-no-fungo/testcases/requests.yml create mode 100644 examples/demo-with-no-funppy/.gitignore rename hrp/internal/build/examples/debugtalk_no_funppy.py => examples/demo-with-no-funppy/debugtalk.py (94%) create mode 100644 examples/demo-with-no-funppy/har/.keep create mode 100644 examples/demo-with-no-funppy/testcases/demo.json create mode 100644 examples/demo-with-no-funppy/testcases/ref_testcase.yml create mode 100644 examples/demo-with-no-funppy/testcases/requests.json create mode 100644 examples/demo-with-no-funppy/testcases/requests.yml create mode 100644 hrp/internal/scaffold/templates/testcases/demo_go_ref_testcase.yml create mode 100644 hrp/internal/scaffold/templates/testcases/demo_go_requests.json create mode 100644 hrp/internal/scaffold/templates/testcases/demo_go_requests.yml create mode 100644 hrp/internal/scaffold/templates/testcases/demo_go_with_funplugin.json diff --git a/docs/cmd/hrp.md b/docs/cmd/hrp.md index c9499319..ce9ba71c 100644 --- a/docs/cmd/hrp.md +++ b/docs/cmd/hrp.md @@ -31,6 +31,7 @@ Copyright 2017 debugtalk * [hrp boom](hrp_boom.md) - run load test with boomer * [hrp convert](hrp_convert.md) - convert to JSON/YAML/gotest/pytest testcases +* [hrp build](hrp_build.md) - build plugin for testing * [hrp har2case](hrp_har2case.md) - convert HAR to json/yaml testcase files * [hrp pytest](hrp_pytest.md) - run API test with pytest * [hrp run](hrp_run.md) - run API test with go engine diff --git a/examples/demo-with-go-plugin/plugin/debugtalk.go b/examples/demo-with-go-plugin/plugin/debugtalk.go index b3b39400..3995ea24 100644 --- a/examples/demo-with-go-plugin/plugin/debugtalk.go +++ b/examples/demo-with-go-plugin/plugin/debugtalk.go @@ -46,12 +46,12 @@ func GetVersion() string { } func main() { - fungo.Register("get_version", GetVersion) - fungo.Register("sum_ints", SumInts) - fungo.Register("sum_two_int", SumTwoInt) - fungo.Register("sum_two", SumTwoInt) - fungo.Register("sum", Sum) - fungo.Register("setup_hook_example", SetupHookExample) - fungo.Register("teardown_hook_example", TeardownHookExample) + fungo.Register("GetVersion", GetVersion) + fungo.Register("SumInts", SumInts) + fungo.Register("SumTwoInt", SumTwoInt) + fungo.Register("SumTwoInt", SumTwoInt) + fungo.Register("Sum", Sum) + fungo.Register("SetupHookExample", SetupHookExample) + fungo.Register("TeardownHookExample", TeardownHookExample) fungo.Serve() } diff --git a/examples/demo-with-go-plugin/testcases/demo.json b/examples/demo-with-go-plugin/testcases/demo.json index 1bb63ed8..0af40519 100644 --- a/examples/demo-with-go-plugin/testcases/demo.json +++ b/examples/demo-with-go-plugin/testcases/demo.json @@ -3,9 +3,9 @@ "name": "demo with complex mechanisms", "base_url": "https://postman-echo.com", "variables": { - "a": "${sum(10, 2.3)}", + "a": "${Sum(10, 2.3)}", "b": 3.45, - "n": "${sum_ints(1, 2, 2)}", + "n": "${SumInts(1, 2, 2)}", "varFoo1": "${gen_random_string($n)}", "varFoo2": "${max($a, $b)}" } @@ -38,10 +38,10 @@ "varFoo2": "${max($a, $b)}" }, "setup_hooks": [ - "${setup_hook_example($name)}" + "${SetupHookExample($name)}" ], "teardown_hooks": [ - "${teardown_hook_example($name)}" + "${TeardownHookExample($name)}" ], "extract": { "varFoo1": "body.args.foo1" diff --git a/examples/demo-with-go-plugin/testcases/ref_testcase.yml b/examples/demo-with-go-plugin/testcases/ref_testcase.yml index 0816481c..010133cf 100644 --- a/examples/demo-with-go-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-go-plugin/testcases/ref_testcase.yml @@ -24,7 +24,7 @@ teststeps: method: POST url: /post headers: - User-Agent: funplugin/${get_version()} + User-Agent: funplugin/${GetVersion()} Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo3" validate: diff --git a/examples/demo-with-go-plugin/testcases/requests.json b/examples/demo-with-go-plugin/testcases/requests.json index 162632b4..d4dcb276 100644 --- a/examples/demo-with-go-plugin/testcases/requests.json +++ b/examples/demo-with-go-plugin/testcases/requests.json @@ -19,7 +19,7 @@ "variables": { "foo1": "${ENV(USERNAME)}", "foo2": "bar21", - "sum_v": "${sum_two_int(1, 2)}" + "sum_v": "${SumTwoInt(1, 2)}" }, "request": { "method": "GET", @@ -30,7 +30,7 @@ "sum_v": "$sum_v" }, "headers": { - "User-Agent": "funplugin/${get_version()}" + "User-Agent": "funplugin/${GetVersion()}" } }, "extract": { @@ -73,7 +73,7 @@ "method": "POST", "url": "/post", "headers": { - "User-Agent": "funplugin/${get_version()}", + "User-Agent": "funplugin/${GetVersion()}", "Content-Type": "text/plain" }, "body": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." @@ -102,7 +102,7 @@ "method": "POST", "url": "/post", "headers": { - "User-Agent": "funplugin/${get_version()}", + "User-Agent": "funplugin/${GetVersion()}", "Content-Type": "application/x-www-form-urlencoded" }, "body": "foo1=$foo1&foo2=$foo2&foo3=$foo3" diff --git a/examples/demo-with-go-plugin/testcases/requests.yml b/examples/demo-with-go-plugin/testcases/requests.yml index 034dbefb..add3a28d 100644 --- a/examples/demo-with-go-plugin/testcases/requests.yml +++ b/examples/demo-with-go-plugin/testcases/requests.yml @@ -14,7 +14,7 @@ teststeps: variables: foo1: ${ENV(USERNAME)} foo2: bar21 - sum_v: "${sum_two_int(1, 2)}" + sum_v: "${SumTwoInt(1, 2)}" request: method: GET url: $base_url/get @@ -23,7 +23,7 @@ teststeps: foo2: $foo2 sum_v: $sum_v headers: - User-Agent: funplugin/${get_version()} + User-Agent: funplugin/${GetVersion()} extract: foo3: "body.args.foo2" validate: @@ -40,7 +40,7 @@ teststeps: method: POST url: $base_url/post headers: - User-Agent: funplugin/${get_version()} + User-Agent: funplugin/${GetVersion()} Content-Type: "text/plain" body: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." validate: @@ -54,7 +54,7 @@ teststeps: method: POST url: $base_url/post headers: - User-Agent: funplugin/${get_version()} + User-Agent: funplugin/${GetVersion()} Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo2&foo3=$foo3" validate: diff --git a/examples/demo-with-no-fungo/.gitignore b/examples/demo-with-no-fungo/.gitignore new file mode 100644 index 00000000..33401380 --- /dev/null +++ b/examples/demo-with-no-fungo/.gitignore @@ -0,0 +1,15 @@ +.env +reports/ +*.so +.vscode/ +.idea/ +.DS_Store +output/ +__pycache__/ +*.pyc +.python-version +logs/ + +# plugin +debugtalk.bin +debugtalk.so diff --git a/examples/demo-with-no-fungo/har/.keep b/examples/demo-with-no-fungo/har/.keep new file mode 100644 index 00000000..e69de29b diff --git a/hrp/internal/build/examples/debugtalk_no_fungo.go b/examples/demo-with-no-fungo/plugin/debugtalk.go similarity index 93% rename from hrp/internal/build/examples/debugtalk_no_fungo.go rename to examples/demo-with-no-fungo/plugin/debugtalk.go index 12d5ce57..5810e0e4 100644 --- a/hrp/internal/build/examples/debugtalk_no_fungo.go +++ b/examples/demo-with-no-fungo/plugin/debugtalk.go @@ -1,10 +1,12 @@ -package examples +package main import ( "fmt" ) -import "os" +func init() { + fmt.Println("init") +} func SumTwoInt(a, b int) int { return a + b @@ -40,7 +42,3 @@ func SetupHookExample(args string) string { func TeardownHookExample(args string) string { return fmt.Sprintf("step name: %v, teardown...", args) } - -func init() { - _, _ = os.Getwd() -} diff --git a/examples/demo-with-no-fungo/testcases/demo.json b/examples/demo-with-no-fungo/testcases/demo.json new file mode 100644 index 00000000..a127d26d --- /dev/null +++ b/examples/demo-with-no-fungo/testcases/demo.json @@ -0,0 +1,176 @@ +{ + "config": { + "name": "demo with complex mechanisms", + "base_url": "https://postman-echo.com", + "variables": { + "a": "${Sum(10, 2.3)}", + "b": 3.45, + "n": "${SumInts(1, 2, 2)}", + "varFoo1": "${GenRandomString($n)}", + "varFoo2": "${Max($a, $b)}" + } + }, + "teststeps": [ + { + "name": "transaction 1 start", + "transaction": { + "name": "tran1", + "type": "start" + } + }, + { + "name": "get with params", + "request": { + "method": "GET", + "url": "/get", + "params": { + "foo1": "$varFoo1", + "foo2": "$varFoo2" + }, + "headers": { + "User-Agent": "HttpRunnerPlus" + } + }, + "variables": { + "b": 34.5, + "n": 3, + "name": "get with params", + "varFoo2": "${Max($a, $b)}" + }, + "setup_hooks": [ + "${SetupHookExample($name)}" + ], + "teardown_hooks": [ + "${TeardownHookExample($name)}" + ], + "extract": { + "varFoo1": "body.args.foo1" + }, + "validate": [ + { + "check": "status_code", + "assert": "equals", + "expect": 200, + "msg": "check response status code" + }, + { + "check": "headers.\"Content-Type\"", + "assert": "startswith", + "expect": "application/json" + }, + { + "check": "body.args.foo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "$varFoo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "body.args.foo2", + "assert": "equals", + "expect": "34.5", + "msg": "check args foo2" + } + ] + }, + { + "name": "transaction 1 end", + "transaction": { + "name": "tran1", + "type": "end" + } + }, + { + "name": "post json data", + "request": { + "method": "POST", + "url": "/post", + "body": { + "foo1": "$varFoo1", + "foo2": "${Max($a, $b)}" + } + }, + "validate": [ + { + "check": "status_code", + "assert": "equals", + "expect": 200, + "msg": "check status code" + }, + { + "check": "body.json.foo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "body.json.foo2", + "assert": "equals", + "expect": 12.3, + "msg": "check args foo2" + } + ] + }, + { + "name": "post form data", + "request": { + "method": "POST", + "url": "/post", + "headers": { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" + }, + "body": { + "foo1": "$varFoo1", + "foo2": "${Max($a, $b)}", + "time": "${GetTimestamp()}" + } + }, + "extract": { + "varTime": "body.form.time" + }, + "validate": [ + { + "check": "status_code", + "assert": "equals", + "expect": 200, + "msg": "check status code" + }, + { + "check": "body.form.foo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "body.form.foo2", + "assert": "equals", + "expect": "12.3", + "msg": "check args foo2" + } + ] + }, + { + "name": "get with timestamp", + "request": { + "method": "GET", + "url": "/get", + "params": { + "time": "$varTime" + } + }, + "validate": [ + { + "check": "body.args.time", + "assert": "length_equals", + "expect": 13, + "msg": "check extracted var timestamp" + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/demo-with-no-fungo/testcases/ref_testcase.yml b/examples/demo-with-no-fungo/testcases/ref_testcase.yml new file mode 100644 index 00000000..957dbdd4 --- /dev/null +++ b/examples/demo-with-no-fungo/testcases/ref_testcase.yml @@ -0,0 +1,33 @@ +config: + name: "request methods testcase: reference testcase" + variables: + foo1: testsuite_config_bar1 + expect_foo1: testsuite_config_bar1 + expect_foo2: config_bar2 + base_url: "https://postman-echo.com" + verify: False + +teststeps: +- + name: request with functions + variables: + foo1: testcase_ref_bar1 + expect_foo1: testcase_ref_bar1 + testcase: testcases/requests.yml + export: + - foo3 +- + name: post form data + variables: + foo1: bar1 + request: + method: POST + url: /post + headers: + User-Agent: funplugin/${GetVersion()} + Content-Type: "application/x-www-form-urlencoded" + data: "foo1=$foo1&foo2=$foo3" + validate: + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "bar1"] + - eq: ["body.form.foo2", "bar21"] diff --git a/examples/demo-with-no-fungo/testcases/requests.json b/examples/demo-with-no-fungo/testcases/requests.json new file mode 100644 index 00000000..f54e6340 --- /dev/null +++ b/examples/demo-with-no-fungo/testcases/requests.json @@ -0,0 +1,138 @@ +{ + "config": { + "name": "request methods testcase with functions", + "variables": { + "foo1": "config_bar1", + "foo2": "config_bar2", + "expect_foo1": "config_bar1", + "expect_foo2": "config_bar2" + }, + "base_url": "https://postman-echo.com", + "verify": false, + "export": [ + "foo3" + ] + }, + "teststeps": [ + { + "name": "get with params", + "variables": { + "foo1": "bar11", + "foo2": "bar21", + "sum_v": "${SumTwoInt(1, 2)}" + }, + "request": { + "method": "GET", + "url": "/get", + "params": { + "foo1": "$foo1", + "foo2": "$foo2", + "sum_v": "$sum_v" + }, + "headers": { + "User-Agent": "funplugin/${GetVersion()}" + } + }, + "extract": { + "foo3": "body.args.foo2" + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.args.foo1", + "bar11" + ] + }, + { + "eq": [ + "body.args.sum_v", + "3" + ] + }, + { + "eq": [ + "body.args.foo2", + "bar21" + ] + } + ] + }, + { + "name": "post raw text", + "variables": { + "foo1": "bar12", + "foo3": "bar32" + }, + "request": { + "method": "POST", + "url": "/post", + "headers": { + "User-Agent": "funplugin/${GetVersion()}", + "Content-Type": "text/plain" + }, + "data": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.data", + "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32." + ] + } + ] + }, + { + "name": "post form data", + "variables": { + "foo2": "bar23" + }, + "request": { + "method": "POST", + "url": "/post", + "headers": { + "User-Agent": "funplugin/${GetVersion()}", + "Content-Type": "application/x-www-form-urlencoded" + }, + "data": "foo1=$foo1&foo2=$foo2&foo3=$foo3" + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.form.foo1", + "$expect_foo1" + ] + }, + { + "eq": [ + "body.form.foo2", + "bar23" + ] + }, + { + "eq": [ + "body.form.foo3", + "bar21" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/demo-with-no-fungo/testcases/requests.yml b/examples/demo-with-no-fungo/testcases/requests.yml new file mode 100644 index 00000000..7884588f --- /dev/null +++ b/examples/demo-with-no-fungo/testcases/requests.yml @@ -0,0 +1,65 @@ +config: + name: "request methods testcase with functions" + variables: + foo1: config_bar1 + foo2: config_bar2 + expect_foo1: config_bar1 + expect_foo2: config_bar2 + base_url: "https://postman-echo.com" + verify: False + export: ["foo3"] + +teststeps: +- + name: get with params + variables: + foo1: bar11 + foo2: bar21 + sum_v: "${SumTwoInt(1, 2)}" + request: + method: GET + url: /get + params: + foo1: $foo1 + foo2: $foo2 + sum_v: $sum_v + headers: + User-Agent: funplugin/${GetVersion()} + extract: + foo3: "body.args.foo2" + validate: + - eq: ["status_code", 200] + - eq: ["body.args.foo1", "bar11"] + - eq: ["body.args.sum_v", "3"] + - eq: ["body.args.foo2", "bar21"] +- + name: post raw text + variables: + foo1: "bar12" + foo3: "bar32" + request: + method: POST + url: /post + headers: + User-Agent: funplugin/${GetVersion()} + Content-Type: "text/plain" + data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." + validate: + - eq: ["status_code", 200] + - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."] +- + name: post form data + variables: + foo2: bar23 + request: + method: POST + url: /post + headers: + User-Agent: funplugin/${GetVersion()} + Content-Type: "application/x-www-form-urlencoded" + data: "foo1=$foo1&foo2=$foo2&foo3=$foo3" + validate: + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "$expect_foo1"] + - eq: ["body.form.foo2", "bar23"] + - eq: ["body.form.foo3", "bar21"] diff --git a/examples/demo-with-no-funppy/.gitignore b/examples/demo-with-no-funppy/.gitignore new file mode 100644 index 00000000..33401380 --- /dev/null +++ b/examples/demo-with-no-funppy/.gitignore @@ -0,0 +1,15 @@ +.env +reports/ +*.so +.vscode/ +.idea/ +.DS_Store +output/ +__pycache__/ +*.pyc +.python-version +logs/ + +# plugin +debugtalk.bin +debugtalk.so diff --git a/hrp/internal/build/examples/debugtalk_no_funppy.py b/examples/demo-with-no-funppy/debugtalk.py similarity index 94% rename from hrp/internal/build/examples/debugtalk_no_funppy.py rename to examples/demo-with-no-funppy/debugtalk.py index 370206d6..8d93ae1f 100644 --- a/hrp/internal/build/examples/debugtalk_no_funppy.py +++ b/examples/demo-with-no-funppy/debugtalk.py @@ -3,6 +3,10 @@ import time from typing import List +def get_version(): + return "httprunner v4.0" + + def sleep(n_secs): time.sleep(n_secs) diff --git a/examples/demo-with-no-funppy/har/.keep b/examples/demo-with-no-funppy/har/.keep new file mode 100644 index 00000000..e69de29b diff --git a/examples/demo-with-no-funppy/testcases/demo.json b/examples/demo-with-no-funppy/testcases/demo.json new file mode 100644 index 00000000..1bb63ed8 --- /dev/null +++ b/examples/demo-with-no-funppy/testcases/demo.json @@ -0,0 +1,176 @@ +{ + "config": { + "name": "demo with complex mechanisms", + "base_url": "https://postman-echo.com", + "variables": { + "a": "${sum(10, 2.3)}", + "b": 3.45, + "n": "${sum_ints(1, 2, 2)}", + "varFoo1": "${gen_random_string($n)}", + "varFoo2": "${max($a, $b)}" + } + }, + "teststeps": [ + { + "name": "transaction 1 start", + "transaction": { + "name": "tran1", + "type": "start" + } + }, + { + "name": "get with params", + "request": { + "method": "GET", + "url": "/get", + "params": { + "foo1": "$varFoo1", + "foo2": "$varFoo2" + }, + "headers": { + "User-Agent": "HttpRunnerPlus" + } + }, + "variables": { + "b": 34.5, + "n": 3, + "name": "get with params", + "varFoo2": "${max($a, $b)}" + }, + "setup_hooks": [ + "${setup_hook_example($name)}" + ], + "teardown_hooks": [ + "${teardown_hook_example($name)}" + ], + "extract": { + "varFoo1": "body.args.foo1" + }, + "validate": [ + { + "check": "status_code", + "assert": "equals", + "expect": 200, + "msg": "check response status code" + }, + { + "check": "headers.\"Content-Type\"", + "assert": "startswith", + "expect": "application/json" + }, + { + "check": "body.args.foo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "$varFoo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "body.args.foo2", + "assert": "equals", + "expect": "34.5", + "msg": "check args foo2" + } + ] + }, + { + "name": "transaction 1 end", + "transaction": { + "name": "tran1", + "type": "end" + } + }, + { + "name": "post json data", + "request": { + "method": "POST", + "url": "/post", + "body": { + "foo1": "$varFoo1", + "foo2": "${max($a, $b)}" + } + }, + "validate": [ + { + "check": "status_code", + "assert": "equals", + "expect": 200, + "msg": "check status code" + }, + { + "check": "body.json.foo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "body.json.foo2", + "assert": "equals", + "expect": 12.3, + "msg": "check args foo2" + } + ] + }, + { + "name": "post form data", + "request": { + "method": "POST", + "url": "/post", + "headers": { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" + }, + "body": { + "foo1": "$varFoo1", + "foo2": "${max($a, $b)}", + "time": "${get_timestamp()}" + } + }, + "extract": { + "varTime": "body.form.time" + }, + "validate": [ + { + "check": "status_code", + "assert": "equals", + "expect": 200, + "msg": "check status code" + }, + { + "check": "body.form.foo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "body.form.foo2", + "assert": "equals", + "expect": "12.3", + "msg": "check args foo2" + } + ] + }, + { + "name": "get with timestamp", + "request": { + "method": "GET", + "url": "/get", + "params": { + "time": "$varTime" + } + }, + "validate": [ + { + "check": "body.args.time", + "assert": "length_equals", + "expect": 13, + "msg": "check extracted var timestamp" + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/demo-with-no-funppy/testcases/ref_testcase.yml b/examples/demo-with-no-funppy/testcases/ref_testcase.yml new file mode 100644 index 00000000..6cf32323 --- /dev/null +++ b/examples/demo-with-no-funppy/testcases/ref_testcase.yml @@ -0,0 +1,33 @@ +config: + name: "request methods testcase: reference testcase" + variables: + foo1: testsuite_config_bar1 + expect_foo1: testsuite_config_bar1 + expect_foo2: config_bar2 + base_url: "https://postman-echo.com" + verify: False + +teststeps: +- + name: request with functions + variables: + foo1: testcase_ref_bar1 + expect_foo1: testcase_ref_bar1 + testcase: testcases/requests.yml + export: + - foo3 +- + name: post form data + variables: + foo1: bar1 + request: + method: POST + url: /post + headers: + User-Agent: funplugin/${get_version()} + Content-Type: "application/x-www-form-urlencoded" + data: "foo1=$foo1&foo2=$foo3" + validate: + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "bar1"] + - eq: ["body.form.foo2", "bar21"] diff --git a/examples/demo-with-no-funppy/testcases/requests.json b/examples/demo-with-no-funppy/testcases/requests.json new file mode 100644 index 00000000..b13f3837 --- /dev/null +++ b/examples/demo-with-no-funppy/testcases/requests.json @@ -0,0 +1,138 @@ +{ + "config": { + "name": "request methods testcase with functions", + "variables": { + "foo1": "config_bar1", + "foo2": "config_bar2", + "expect_foo1": "config_bar1", + "expect_foo2": "config_bar2" + }, + "base_url": "https://postman-echo.com", + "verify": false, + "export": [ + "foo3" + ] + }, + "teststeps": [ + { + "name": "get with params", + "variables": { + "foo1": "bar11", + "foo2": "bar21", + "sum_v": "${sum_two_int(1, 2)}" + }, + "request": { + "method": "GET", + "url": "/get", + "params": { + "foo1": "$foo1", + "foo2": "$foo2", + "sum_v": "$sum_v" + }, + "headers": { + "User-Agent": "funplugin/${get_version()}" + } + }, + "extract": { + "foo3": "body.args.foo2" + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.args.foo1", + "bar11" + ] + }, + { + "eq": [ + "body.args.sum_v", + "3" + ] + }, + { + "eq": [ + "body.args.foo2", + "bar21" + ] + } + ] + }, + { + "name": "post raw text", + "variables": { + "foo1": "bar12", + "foo3": "bar32" + }, + "request": { + "method": "POST", + "url": "/post", + "headers": { + "User-Agent": "funplugin/${get_version()}", + "Content-Type": "text/plain" + }, + "data": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.data", + "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32." + ] + } + ] + }, + { + "name": "post form data", + "variables": { + "foo2": "bar23" + }, + "request": { + "method": "POST", + "url": "/post", + "headers": { + "User-Agent": "funplugin/${get_version()}", + "Content-Type": "application/x-www-form-urlencoded" + }, + "data": "foo1=$foo1&foo2=$foo2&foo3=$foo3" + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.form.foo1", + "$expect_foo1" + ] + }, + { + "eq": [ + "body.form.foo2", + "bar23" + ] + }, + { + "eq": [ + "body.form.foo3", + "bar21" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/demo-with-no-funppy/testcases/requests.yml b/examples/demo-with-no-funppy/testcases/requests.yml new file mode 100644 index 00000000..86d1b9cc --- /dev/null +++ b/examples/demo-with-no-funppy/testcases/requests.yml @@ -0,0 +1,65 @@ +config: + name: "request methods testcase with functions" + variables: + foo1: config_bar1 + foo2: config_bar2 + expect_foo1: config_bar1 + expect_foo2: config_bar2 + base_url: "https://postman-echo.com" + verify: False + export: ["foo3"] + +teststeps: +- + name: get with params + variables: + foo1: bar11 + foo2: bar21 + sum_v: "${sum_two_int(1, 2)}" + request: + method: GET + url: /get + params: + foo1: $foo1 + foo2: $foo2 + sum_v: $sum_v + headers: + User-Agent: funplugin/${get_version()} + extract: + foo3: "body.args.foo2" + validate: + - eq: ["status_code", 200] + - eq: ["body.args.foo1", "bar11"] + - eq: ["body.args.sum_v", "3"] + - eq: ["body.args.foo2", "bar21"] +- + name: post raw text + variables: + foo1: "bar12" + foo3: "bar32" + request: + method: POST + url: /post + headers: + User-Agent: funplugin/${get_version()} + Content-Type: "text/plain" + data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." + validate: + - eq: ["status_code", 200] + - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."] +- + name: post form data + variables: + foo2: bar23 + request: + method: POST + url: /post + headers: + User-Agent: funplugin/${get_version()} + Content-Type: "application/x-www-form-urlencoded" + data: "foo1=$foo1&foo2=$foo2&foo3=$foo3" + validate: + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "$expect_foo1"] + - eq: ["body.form.foo2", "bar23"] + - eq: ["body.form.foo3", "bar21"] diff --git a/hrp/boomer_test.go b/hrp/boomer_test.go index 4edefa38..b70fc832 100644 --- a/hrp/boomer_test.go +++ b/hrp/boomer_test.go @@ -25,7 +25,7 @@ func TestBoomerStandaloneRun(t *testing.T) { NewStep("TestCase3").CallRefCase(&TestCase{Config: NewConfig("TestCase3")}), }, } - testcase2 := &demoTestCaseWithPluginJSONPath + testcase2 := &demoTestCaseWithGoPluginJSONPath b := NewBoomer(2, 1) go b.Run(testcase1, testcase2) diff --git a/hrp/internal/build/main.go b/hrp/internal/build/main.go index 811801ab..39c2e92a 100644 --- a/hrp/internal/build/main.go +++ b/hrp/internal/build/main.go @@ -62,7 +62,7 @@ func (t *TemplateContent) parseGoContent(path string) error { originalContent := string(content) // parse imports - importSlice := t.Regexps.Import.FindAllStringSubmatch(originalContent, -1) + importSlice := t.Regexps.Imports.FindAllStringSubmatch(originalContent, -1) if len(importSlice) != 0 { imports := strings.Replace(importSlice[0][1], "\t", "", -1) for _, elem := range strings.Split(imports, "\n") { @@ -70,7 +70,7 @@ func (t *TemplateContent) parseGoContent(path string) error { } } // parse import - importSlice = t.Regexps.Imports.FindAllStringSubmatch(originalContent, -1) + importSlice = t.Regexps.Import.FindAllStringSubmatch(originalContent, -1) if len(importSlice) != 0 { for _, elem := range importSlice { t.Imports = append(t.Imports, strings.TrimSpace(elem[1])) diff --git a/hrp/internal/build/main_test.go b/hrp/internal/build/main_test.go index a169c77a..b26109a2 100644 --- a/hrp/internal/build/main_test.go +++ b/hrp/internal/build/main_test.go @@ -1,29 +1,51 @@ package build import ( + "github.com/httprunner/httprunner/v4/hrp/internal/builtin" + "regexp" "testing" "github.com/stretchr/testify/assert" ) func TestRun(t *testing.T) { - err := Run("examples/debugtalk_no_funppy.py", "") + err := Run("../../../examples/demo-with-no-fungo/plugin/debugtalk.go", "") if !assert.Nil(t, err) { t.Fatal() } - err = Run("examples/debugtalk_no_fungo.go", "") + err = Run("../../../examples/demo-with-no-funppy/debugtalk.py", "") if !assert.Nil(t, err) { t.Fatal() } - err = Run("examples/debugtalk_no_funppy.py", "./debugtalk.py") + err = Run("../../../examples/demo-with-no-fungo/plugin/debugtalk.go", "./debugtalk_gen.bin") if !assert.Nil(t, err) { t.Fatal() } - err = Run("examples/debugtalk_no_fungo.go", "./debugtalk_gen.bin") + err = Run("../../../examples/demo-with-no-funppy/debugtalk.py", "./debugtalk_gen.py") if !assert.Nil(t, err) { t.Fatal() } + + contentBytes, err := builtin.ReadFile("./debugtalk_gen.py") + if !assert.Nil(t, err) { + t.Fatal() + } + + content := string(contentBytes) + if !assert.Contains(t, content, "import funppy") { + t.Fatal() + } + + if !assert.Contains(t, content, "funppy.register") { + t.Fatal() + } + + reg, _ := regexp.Compile(`funppy\.register`) + matchedSlice := reg.FindAllStringSubmatch(content, -1) + if !assert.Len(t, matchedSlice, 10) { + t.Fatal() + } } diff --git a/hrp/internal/builtin/utils.go b/hrp/internal/builtin/utils.go index d4920084..09176168 100644 --- a/hrp/internal/builtin/utils.go +++ b/hrp/internal/builtin/utils.go @@ -281,7 +281,7 @@ var ErrUnsupportedFileExt = fmt.Errorf("unsupported file extension") // LoadFile loads file content with file extension and assigns to structObj func LoadFile(path string, structObj interface{}) (err error) { log.Info().Str("path", path).Msg("load file") - file, err := readFile(path) + file, err := ReadFile(path) if err != nil { return errors.Wrap(err, "read file failed") } @@ -335,7 +335,7 @@ func parseEnvContent(file []byte, obj interface{}) error { func loadFromCSV(path string) []map[string]interface{} { log.Info().Str("path", path).Msg("load csv file") - file, err := readFile(path) + file, err := ReadFile(path) if err != nil { log.Error().Err(err).Msg("read csv file failed") os.Exit(1) @@ -361,7 +361,7 @@ func loadFromCSV(path string) []map[string]interface{} { func loadMessage(path string) []byte { log.Info().Str("path", path).Msg("load message file") - file, err := readFile(path) + file, err := ReadFile(path) if err != nil { log.Error().Err(err).Msg("read message file failed") os.Exit(1) @@ -369,7 +369,7 @@ func loadMessage(path string) []byte { return file } -func readFile(path string) ([]byte, error) { +func ReadFile(path string) ([]byte, error) { var err error path, err = filepath.Abs(path) if err != nil { diff --git a/hrp/internal/scaffold/templates/plugin/debugtalk.go b/hrp/internal/scaffold/templates/plugin/debugtalk.go index b3b39400..3995ea24 100644 --- a/hrp/internal/scaffold/templates/plugin/debugtalk.go +++ b/hrp/internal/scaffold/templates/plugin/debugtalk.go @@ -46,12 +46,12 @@ func GetVersion() string { } func main() { - fungo.Register("get_version", GetVersion) - fungo.Register("sum_ints", SumInts) - fungo.Register("sum_two_int", SumTwoInt) - fungo.Register("sum_two", SumTwoInt) - fungo.Register("sum", Sum) - fungo.Register("setup_hook_example", SetupHookExample) - fungo.Register("teardown_hook_example", TeardownHookExample) + fungo.Register("GetVersion", GetVersion) + fungo.Register("SumInts", SumInts) + fungo.Register("SumTwoInt", SumTwoInt) + fungo.Register("SumTwoInt", SumTwoInt) + fungo.Register("Sum", Sum) + fungo.Register("SetupHookExample", SetupHookExample) + fungo.Register("TeardownHookExample", TeardownHookExample) fungo.Serve() } diff --git a/hrp/internal/scaffold/templates/testcases/demo_go_ref_testcase.yml b/hrp/internal/scaffold/templates/testcases/demo_go_ref_testcase.yml new file mode 100644 index 00000000..957dbdd4 --- /dev/null +++ b/hrp/internal/scaffold/templates/testcases/demo_go_ref_testcase.yml @@ -0,0 +1,33 @@ +config: + name: "request methods testcase: reference testcase" + variables: + foo1: testsuite_config_bar1 + expect_foo1: testsuite_config_bar1 + expect_foo2: config_bar2 + base_url: "https://postman-echo.com" + verify: False + +teststeps: +- + name: request with functions + variables: + foo1: testcase_ref_bar1 + expect_foo1: testcase_ref_bar1 + testcase: testcases/requests.yml + export: + - foo3 +- + name: post form data + variables: + foo1: bar1 + request: + method: POST + url: /post + headers: + User-Agent: funplugin/${GetVersion()} + Content-Type: "application/x-www-form-urlencoded" + data: "foo1=$foo1&foo2=$foo3" + validate: + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "bar1"] + - eq: ["body.form.foo2", "bar21"] diff --git a/hrp/internal/scaffold/templates/testcases/demo_go_requests.json b/hrp/internal/scaffold/templates/testcases/demo_go_requests.json new file mode 100644 index 00000000..f54e6340 --- /dev/null +++ b/hrp/internal/scaffold/templates/testcases/demo_go_requests.json @@ -0,0 +1,138 @@ +{ + "config": { + "name": "request methods testcase with functions", + "variables": { + "foo1": "config_bar1", + "foo2": "config_bar2", + "expect_foo1": "config_bar1", + "expect_foo2": "config_bar2" + }, + "base_url": "https://postman-echo.com", + "verify": false, + "export": [ + "foo3" + ] + }, + "teststeps": [ + { + "name": "get with params", + "variables": { + "foo1": "bar11", + "foo2": "bar21", + "sum_v": "${SumTwoInt(1, 2)}" + }, + "request": { + "method": "GET", + "url": "/get", + "params": { + "foo1": "$foo1", + "foo2": "$foo2", + "sum_v": "$sum_v" + }, + "headers": { + "User-Agent": "funplugin/${GetVersion()}" + } + }, + "extract": { + "foo3": "body.args.foo2" + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.args.foo1", + "bar11" + ] + }, + { + "eq": [ + "body.args.sum_v", + "3" + ] + }, + { + "eq": [ + "body.args.foo2", + "bar21" + ] + } + ] + }, + { + "name": "post raw text", + "variables": { + "foo1": "bar12", + "foo3": "bar32" + }, + "request": { + "method": "POST", + "url": "/post", + "headers": { + "User-Agent": "funplugin/${GetVersion()}", + "Content-Type": "text/plain" + }, + "data": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.data", + "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32." + ] + } + ] + }, + { + "name": "post form data", + "variables": { + "foo2": "bar23" + }, + "request": { + "method": "POST", + "url": "/post", + "headers": { + "User-Agent": "funplugin/${GetVersion()}", + "Content-Type": "application/x-www-form-urlencoded" + }, + "data": "foo1=$foo1&foo2=$foo2&foo3=$foo3" + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.form.foo1", + "$expect_foo1" + ] + }, + { + "eq": [ + "body.form.foo2", + "bar23" + ] + }, + { + "eq": [ + "body.form.foo3", + "bar21" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/hrp/internal/scaffold/templates/testcases/demo_go_requests.yml b/hrp/internal/scaffold/templates/testcases/demo_go_requests.yml new file mode 100644 index 00000000..7884588f --- /dev/null +++ b/hrp/internal/scaffold/templates/testcases/demo_go_requests.yml @@ -0,0 +1,65 @@ +config: + name: "request methods testcase with functions" + variables: + foo1: config_bar1 + foo2: config_bar2 + expect_foo1: config_bar1 + expect_foo2: config_bar2 + base_url: "https://postman-echo.com" + verify: False + export: ["foo3"] + +teststeps: +- + name: get with params + variables: + foo1: bar11 + foo2: bar21 + sum_v: "${SumTwoInt(1, 2)}" + request: + method: GET + url: /get + params: + foo1: $foo1 + foo2: $foo2 + sum_v: $sum_v + headers: + User-Agent: funplugin/${GetVersion()} + extract: + foo3: "body.args.foo2" + validate: + - eq: ["status_code", 200] + - eq: ["body.args.foo1", "bar11"] + - eq: ["body.args.sum_v", "3"] + - eq: ["body.args.foo2", "bar21"] +- + name: post raw text + variables: + foo1: "bar12" + foo3: "bar32" + request: + method: POST + url: /post + headers: + User-Agent: funplugin/${GetVersion()} + Content-Type: "text/plain" + data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." + validate: + - eq: ["status_code", 200] + - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."] +- + name: post form data + variables: + foo2: bar23 + request: + method: POST + url: /post + headers: + User-Agent: funplugin/${GetVersion()} + Content-Type: "application/x-www-form-urlencoded" + data: "foo1=$foo1&foo2=$foo2&foo3=$foo3" + validate: + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "$expect_foo1"] + - eq: ["body.form.foo2", "bar23"] + - eq: ["body.form.foo3", "bar21"] diff --git a/hrp/internal/scaffold/templates/testcases/demo_go_with_funplugin.json b/hrp/internal/scaffold/templates/testcases/demo_go_with_funplugin.json new file mode 100644 index 00000000..0af40519 --- /dev/null +++ b/hrp/internal/scaffold/templates/testcases/demo_go_with_funplugin.json @@ -0,0 +1,176 @@ +{ + "config": { + "name": "demo with complex mechanisms", + "base_url": "https://postman-echo.com", + "variables": { + "a": "${Sum(10, 2.3)}", + "b": 3.45, + "n": "${SumInts(1, 2, 2)}", + "varFoo1": "${gen_random_string($n)}", + "varFoo2": "${max($a, $b)}" + } + }, + "teststeps": [ + { + "name": "transaction 1 start", + "transaction": { + "name": "tran1", + "type": "start" + } + }, + { + "name": "get with params", + "request": { + "method": "GET", + "url": "/get", + "params": { + "foo1": "$varFoo1", + "foo2": "$varFoo2" + }, + "headers": { + "User-Agent": "HttpRunnerPlus" + } + }, + "variables": { + "b": 34.5, + "n": 3, + "name": "get with params", + "varFoo2": "${max($a, $b)}" + }, + "setup_hooks": [ + "${SetupHookExample($name)}" + ], + "teardown_hooks": [ + "${TeardownHookExample($name)}" + ], + "extract": { + "varFoo1": "body.args.foo1" + }, + "validate": [ + { + "check": "status_code", + "assert": "equals", + "expect": 200, + "msg": "check response status code" + }, + { + "check": "headers.\"Content-Type\"", + "assert": "startswith", + "expect": "application/json" + }, + { + "check": "body.args.foo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "$varFoo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "body.args.foo2", + "assert": "equals", + "expect": "34.5", + "msg": "check args foo2" + } + ] + }, + { + "name": "transaction 1 end", + "transaction": { + "name": "tran1", + "type": "end" + } + }, + { + "name": "post json data", + "request": { + "method": "POST", + "url": "/post", + "body": { + "foo1": "$varFoo1", + "foo2": "${max($a, $b)}" + } + }, + "validate": [ + { + "check": "status_code", + "assert": "equals", + "expect": 200, + "msg": "check status code" + }, + { + "check": "body.json.foo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "body.json.foo2", + "assert": "equals", + "expect": 12.3, + "msg": "check args foo2" + } + ] + }, + { + "name": "post form data", + "request": { + "method": "POST", + "url": "/post", + "headers": { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" + }, + "body": { + "foo1": "$varFoo1", + "foo2": "${max($a, $b)}", + "time": "${get_timestamp()}" + } + }, + "extract": { + "varTime": "body.form.time" + }, + "validate": [ + { + "check": "status_code", + "assert": "equals", + "expect": 200, + "msg": "check status code" + }, + { + "check": "body.form.foo1", + "assert": "length_equals", + "expect": 5, + "msg": "check args foo1" + }, + { + "check": "body.form.foo2", + "assert": "equals", + "expect": "12.3", + "msg": "check args foo2" + } + ] + }, + { + "name": "get with timestamp", + "request": { + "method": "GET", + "url": "/get", + "params": { + "time": "$varTime" + } + }, + "validate": [ + { + "check": "body.args.time", + "assert": "length_equals", + "expect": 13, + "msg": "check extracted var timestamp" + } + ] + } + ] +} \ No newline at end of file diff --git a/hrp/plugin.go b/hrp/plugin.go index 004fc1cb..72d6767d 100644 --- a/hrp/plugin.go +++ b/hrp/plugin.go @@ -2,9 +2,11 @@ package hrp import ( "fmt" + "github.com/httprunner/httprunner/v4/hrp/internal/build" "os" "os/signal" "path/filepath" + "strings" "syscall" "github.com/httprunner/funplugin" @@ -32,6 +34,21 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir st // TODO: move pluginDir to funplugin pluginDir = filepath.Dir(pluginPath) + // compatible the format of debugtalk.py with v2/v3 + ext := filepath.Ext(pluginPath) + if ext == ".py" { + // skip if only debugtalk_gen.py exists + if !strings.HasSuffix(pluginPath, "debugtalk_gen.py") { + genPyPluginPath := filepath.Join(pluginDir, "debugtalk_gen.py") + err = build.Run(pluginPath, genPyPluginPath) + if err != nil { + log.Error().Err(err).Msgf(fmt.Sprintf("failed to build %s", pluginPath)) + return + } + pluginPath = genPyPluginPath + } + } + // found plugin file plugin, err = funplugin.Init(pluginPath, funplugin.WithLogOn(logOn)) if err != nil { @@ -62,19 +79,19 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir st } func locatePlugin(path string) (pluginPath string, err error) { - // priority: hashicorp plugin (debugtalk.bin > debugtalk_gen.py > debugtalk.py) > go plugin (debugtalk.so) + // priority: hashicorp plugin (debugtalk.bin > debugtalk.py > debugtalk_gen.py) > go plugin (debugtalk.so) pluginPath, err = locateFile(path, hashicorpGoPluginFile) if err == nil { return } - pluginPath, err = locateFile(path, hashicorpPyPluginFile) + pluginPath, err = locateFile(path, debugtalkPyFile) if err == nil { return } - pluginPath, err = locateFile(path, debugtalkPyFile) + pluginPath, err = locateFile(path, hashicorpPyPluginFile) if err == nil { return } diff --git a/hrp/runner_test.go b/hrp/runner_test.go index d03f8d75..4c043090 100644 --- a/hrp/runner_test.go +++ b/hrp/runner_test.go @@ -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 { diff --git a/hrp/testcase_test.go b/hrp/testcase_test.go index eb6a69ae..6564612e 100644 --- a/hrp/testcase_test.go +++ b/hrp/testcase_test.go @@ -15,6 +15,7 @@ const ( var ( demoTestCaseWithPluginJSONPath TestCasePath = templatesDir + "testcases/demo_with_funplugin.json" + demoTestCaseWithGoPluginJSONPath TestCasePath = templatesDir + "testcases/demo_go_with_funplugin.json" demoTestCaseWithPluginYAMLPath TestCasePath = templatesDir + "testcases/demo_with_funplugin.yaml" demoTestCaseWithoutPluginJSONPath TestCasePath = templatesDir + "testcases/demo_without_funplugin.json" demoTestCaseWithoutPluginYAMLPath TestCasePath = templatesDir + "testcases/demo_without_funplugin.yaml" From 4bb7d8e6199d96d5fe09d19d4c69e2e51babbcbd Mon Sep 17 00:00:00 2001 From: xucong053 Date: Fri, 27 May 2022 11:22:31 +0800 Subject: [PATCH 5/6] update docs --- docs/cmd/hrp_build.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 docs/cmd/hrp_build.md diff --git a/docs/cmd/hrp_build.md b/docs/cmd/hrp_build.md new file mode 100644 index 00000000..c60b3e3c --- /dev/null +++ b/docs/cmd/hrp_build.md @@ -0,0 +1,31 @@ +## hrp build + +build plugin for testing + +### Synopsis + +build python/go plugin for testing + +``` +hrp build $path ... [flags] +``` + +### Examples + +``` + $ hrp build plugin/debugtalk.go + $ hrp build plugin/debugtalk.py +``` + +### Options + +``` + -h, --help help for build + -o, --output string funplugin product output path, default: cwd +``` + +### SEE ALSO + +* [hrp](hrp.md) - Next-Generation API Testing Solution. + +###### Auto generated by spf13/cobra on 27-May-2022 From 08ff6fe5f574a7b7b1c3275ebd2cda82dd50950b Mon Sep 17 00:00:00 2001 From: xucong053 Date: Fri, 27 May 2022 16:40:17 +0800 Subject: [PATCH 6/6] fix: unittest --- docs/cmd/hrp.md | 4 +- docs/cmd/hrp_boom.md | 2 +- docs/cmd/hrp_build.md | 2 +- docs/cmd/hrp_convert.md | 2 +- docs/cmd/hrp_har2case.md | 2 +- docs/cmd/hrp_pytest.md | 2 +- docs/cmd/hrp_run.md | 2 +- docs/cmd/hrp_startproject.md | 2 +- docs/cmd/hrp_wiki.md | 2 +- .../demo-with-go-plugin/plugin/debugtalk.go | 14 +- examples/demo-with-go-plugin/plugin/go.mod | 2 +- examples/demo-with-go-plugin/plugin/go.sum | 4 +- examples/demo-with-go-plugin/proj.json | 2 +- .../demo-with-go-plugin/testcases/demo.json | 8 +- .../testcases/ref_testcase.yml | 2 +- .../testcases/requests.json | 8 +- .../testcases/requests.yml | 8 +- examples/demo-with-no-fungo/.gitignore | 15 -- examples/demo-with-no-fungo/har/.keep | 0 .../demo-with-no-fungo/testcases/demo.json | 176 ------------------ .../testcases/ref_testcase.yml | 33 ---- .../testcases/requests.json | 138 -------------- .../demo-with-no-fungo/testcases/requests.yml | 65 ------- examples/demo-with-no-funppy/.gitignore | 15 -- examples/demo-with-no-funppy/har/.keep | 0 .../demo-with-no-funppy/testcases/demo.json | 176 ------------------ .../testcases/ref_testcase.yml | 33 ---- .../testcases/requests.json | 138 -------------- .../testcases/requests.yml | 65 ------- examples/demo-with-py-plugin/proj.json | 2 +- examples/demo-without-plugin/proj.json | 2 +- go.mod | 2 +- go.sum | 4 +- hrp/boomer_test.go | 2 +- hrp/internal/build/main.go | 6 +- hrp/internal/build/main_test.go | 17 +- .../internal/build}/plugin/debugtalk.go | 10 +- .../internal/build/plugin}/debugtalk.py | 2 +- .../scaffold/templates/plugin/debugtalk.go | 14 +- .../testcases/demo_go_ref_testcase.yml | 33 ---- .../templates/testcases/demo_go_requests.json | 138 -------------- .../templates/testcases/demo_go_requests.yml | 65 ------- .../testcases/demo_go_with_funplugin.json | 176 ------------------ hrp/parser.go | 10 +- hrp/plugin.go | 3 +- hrp/runner_test.go | 44 ++--- hrp/testcase_test.go | 1 - 47 files changed, 87 insertions(+), 1366 deletions(-) delete mode 100644 examples/demo-with-no-fungo/.gitignore delete mode 100644 examples/demo-with-no-fungo/har/.keep delete mode 100644 examples/demo-with-no-fungo/testcases/demo.json delete mode 100644 examples/demo-with-no-fungo/testcases/ref_testcase.yml delete mode 100644 examples/demo-with-no-fungo/testcases/requests.json delete mode 100644 examples/demo-with-no-fungo/testcases/requests.yml delete mode 100644 examples/demo-with-no-funppy/.gitignore delete mode 100644 examples/demo-with-no-funppy/har/.keep delete mode 100644 examples/demo-with-no-funppy/testcases/demo.json delete mode 100644 examples/demo-with-no-funppy/testcases/ref_testcase.yml delete mode 100644 examples/demo-with-no-funppy/testcases/requests.json delete mode 100644 examples/demo-with-no-funppy/testcases/requests.yml rename {examples/demo-with-no-fungo => hrp/internal/build}/plugin/debugtalk.go (91%) rename {examples/demo-with-no-funppy => hrp/internal/build/plugin}/debugtalk.py (96%) delete mode 100644 hrp/internal/scaffold/templates/testcases/demo_go_ref_testcase.yml delete mode 100644 hrp/internal/scaffold/templates/testcases/demo_go_requests.json delete mode 100644 hrp/internal/scaffold/templates/testcases/demo_go_requests.yml delete mode 100644 hrp/internal/scaffold/templates/testcases/demo_go_with_funplugin.json diff --git a/docs/cmd/hrp.md b/docs/cmd/hrp.md index ce9ba71c..db7329f8 100644 --- a/docs/cmd/hrp.md +++ b/docs/cmd/hrp.md @@ -30,12 +30,12 @@ Copyright 2017 debugtalk ### SEE ALSO * [hrp boom](hrp_boom.md) - run load test with boomer -* [hrp convert](hrp_convert.md) - convert to JSON/YAML/gotest/pytest testcases * [hrp build](hrp_build.md) - build plugin for testing +* [hrp convert](hrp_convert.md) - convert to JSON/YAML/gotest/pytest testcases * [hrp har2case](hrp_har2case.md) - convert HAR to json/yaml testcase files * [hrp pytest](hrp_pytest.md) - run API test with pytest * [hrp run](hrp_run.md) - run API test with go engine * [hrp startproject](hrp_startproject.md) - create a scaffold project * [hrp wiki](hrp_wiki.md) - visit https://httprunner.com -###### Auto generated by spf13/cobra on 27-May-2022 +###### Auto generated by spf13/cobra on 28-May-2022 diff --git a/docs/cmd/hrp_boom.md b/docs/cmd/hrp_boom.md index 429a0ed3..6f30b821 100644 --- a/docs/cmd/hrp_boom.md +++ b/docs/cmd/hrp_boom.md @@ -42,4 +42,4 @@ hrp boom [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 27-May-2022 +###### Auto generated by spf13/cobra on 28-May-2022 diff --git a/docs/cmd/hrp_build.md b/docs/cmd/hrp_build.md index c60b3e3c..f3b222fe 100644 --- a/docs/cmd/hrp_build.md +++ b/docs/cmd/hrp_build.md @@ -28,4 +28,4 @@ hrp build $path ... [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 27-May-2022 +###### Auto generated by spf13/cobra on 28-May-2022 diff --git a/docs/cmd/hrp_convert.md b/docs/cmd/hrp_convert.md index 3083456c..c52a5348 100644 --- a/docs/cmd/hrp_convert.md +++ b/docs/cmd/hrp_convert.md @@ -22,4 +22,4 @@ hrp convert $path... [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 27-May-2022 +###### Auto generated by spf13/cobra on 28-May-2022 diff --git a/docs/cmd/hrp_har2case.md b/docs/cmd/hrp_har2case.md index 592c5281..2d4cd832 100644 --- a/docs/cmd/hrp_har2case.md +++ b/docs/cmd/hrp_har2case.md @@ -24,4 +24,4 @@ hrp har2case $har_path... [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 27-May-2022 +###### Auto generated by spf13/cobra on 28-May-2022 diff --git a/docs/cmd/hrp_pytest.md b/docs/cmd/hrp_pytest.md index 711c8bac..87c1e906 100644 --- a/docs/cmd/hrp_pytest.md +++ b/docs/cmd/hrp_pytest.md @@ -16,4 +16,4 @@ hrp pytest $path ... [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 27-May-2022 +###### Auto generated by spf13/cobra on 28-May-2022 diff --git a/docs/cmd/hrp_run.md b/docs/cmd/hrp_run.md index 63da347e..21a42988 100644 --- a/docs/cmd/hrp_run.md +++ b/docs/cmd/hrp_run.md @@ -35,4 +35,4 @@ hrp run $path... [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 27-May-2022 +###### Auto generated by spf13/cobra on 28-May-2022 diff --git a/docs/cmd/hrp_startproject.md b/docs/cmd/hrp_startproject.md index e55c5429..45c1fdb3 100644 --- a/docs/cmd/hrp_startproject.md +++ b/docs/cmd/hrp_startproject.md @@ -21,4 +21,4 @@ hrp startproject $project_name [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 27-May-2022 +###### Auto generated by spf13/cobra on 28-May-2022 diff --git a/docs/cmd/hrp_wiki.md b/docs/cmd/hrp_wiki.md index 2eecbdd0..16fdf14d 100644 --- a/docs/cmd/hrp_wiki.md +++ b/docs/cmd/hrp_wiki.md @@ -16,4 +16,4 @@ hrp wiki [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 27-May-2022 +###### Auto generated by spf13/cobra on 28-May-2022 diff --git a/examples/demo-with-go-plugin/plugin/debugtalk.go b/examples/demo-with-go-plugin/plugin/debugtalk.go index 3995ea24..b3b39400 100644 --- a/examples/demo-with-go-plugin/plugin/debugtalk.go +++ b/examples/demo-with-go-plugin/plugin/debugtalk.go @@ -46,12 +46,12 @@ func GetVersion() string { } func main() { - fungo.Register("GetVersion", GetVersion) - fungo.Register("SumInts", SumInts) - fungo.Register("SumTwoInt", SumTwoInt) - fungo.Register("SumTwoInt", SumTwoInt) - fungo.Register("Sum", Sum) - fungo.Register("SetupHookExample", SetupHookExample) - fungo.Register("TeardownHookExample", TeardownHookExample) + fungo.Register("get_version", GetVersion) + fungo.Register("sum_ints", SumInts) + fungo.Register("sum_two_int", SumTwoInt) + fungo.Register("sum_two", SumTwoInt) + fungo.Register("sum", Sum) + fungo.Register("setup_hook_example", SetupHookExample) + fungo.Register("teardown_hook_example", TeardownHookExample) fungo.Serve() } diff --git a/examples/demo-with-go-plugin/plugin/go.mod b/examples/demo-with-go-plugin/plugin/go.mod index 08a135d0..a36c1c27 100644 --- a/examples/demo-with-go-plugin/plugin/go.mod +++ b/examples/demo-with-go-plugin/plugin/go.mod @@ -2,4 +2,4 @@ module plugin go 1.16 -require github.com/httprunner/funplugin v0.4.6 // indirect +require github.com/httprunner/funplugin v0.4.7 // indirect diff --git a/examples/demo-with-go-plugin/plugin/go.sum b/examples/demo-with-go-plugin/plugin/go.sum index 59ea6478..bae78b47 100644 --- a/examples/demo-with-go-plugin/plugin/go.sum +++ b/examples/demo-with-go-plugin/plugin/go.sum @@ -58,8 +58,8 @@ github.com/hashicorp/go-plugin v1.4.3 h1:DXmvivbWD5qdiBts9TpBC7BYL1Aia5sxbRgQB+v github.com/hashicorp/go-plugin v1.4.3/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/httprunner/funplugin v0.4.6 h1:wwpjzo3G9a5BCXBkHs845w4ifKaCtVa/yQjREQjQOgo= -github.com/httprunner/funplugin v0.4.6/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc= +github.com/httprunner/funplugin v0.4.7 h1:bmk84BL8oPGE/rgxCuHgPcwJtBnwDzm/ocmFY/cKcos= +github.com/httprunner/funplugin v0.4.7/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc= github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= diff --git a/examples/demo-with-go-plugin/proj.json b/examples/demo-with-go-plugin/proj.json index 2b2fcb6b..6e7a483a 100644 --- a/examples/demo-with-go-plugin/proj.json +++ b/examples/demo-with-go-plugin/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-with-go-plugin", "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-go-plugin", - "create_time": "2022-05-27T11:34:23.903959+08:00", + "create_time": "2022-05-28T02:00:18.084185+08:00", "hrp_version": "v4.1.0-beta" } \ No newline at end of file diff --git a/examples/demo-with-go-plugin/testcases/demo.json b/examples/demo-with-go-plugin/testcases/demo.json index 0af40519..1bb63ed8 100644 --- a/examples/demo-with-go-plugin/testcases/demo.json +++ b/examples/demo-with-go-plugin/testcases/demo.json @@ -3,9 +3,9 @@ "name": "demo with complex mechanisms", "base_url": "https://postman-echo.com", "variables": { - "a": "${Sum(10, 2.3)}", + "a": "${sum(10, 2.3)}", "b": 3.45, - "n": "${SumInts(1, 2, 2)}", + "n": "${sum_ints(1, 2, 2)}", "varFoo1": "${gen_random_string($n)}", "varFoo2": "${max($a, $b)}" } @@ -38,10 +38,10 @@ "varFoo2": "${max($a, $b)}" }, "setup_hooks": [ - "${SetupHookExample($name)}" + "${setup_hook_example($name)}" ], "teardown_hooks": [ - "${TeardownHookExample($name)}" + "${teardown_hook_example($name)}" ], "extract": { "varFoo1": "body.args.foo1" diff --git a/examples/demo-with-go-plugin/testcases/ref_testcase.yml b/examples/demo-with-go-plugin/testcases/ref_testcase.yml index 010133cf..0816481c 100644 --- a/examples/demo-with-go-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-go-plugin/testcases/ref_testcase.yml @@ -24,7 +24,7 @@ teststeps: method: POST url: /post headers: - User-Agent: funplugin/${GetVersion()} + User-Agent: funplugin/${get_version()} Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo3" validate: diff --git a/examples/demo-with-go-plugin/testcases/requests.json b/examples/demo-with-go-plugin/testcases/requests.json index d4dcb276..162632b4 100644 --- a/examples/demo-with-go-plugin/testcases/requests.json +++ b/examples/demo-with-go-plugin/testcases/requests.json @@ -19,7 +19,7 @@ "variables": { "foo1": "${ENV(USERNAME)}", "foo2": "bar21", - "sum_v": "${SumTwoInt(1, 2)}" + "sum_v": "${sum_two_int(1, 2)}" }, "request": { "method": "GET", @@ -30,7 +30,7 @@ "sum_v": "$sum_v" }, "headers": { - "User-Agent": "funplugin/${GetVersion()}" + "User-Agent": "funplugin/${get_version()}" } }, "extract": { @@ -73,7 +73,7 @@ "method": "POST", "url": "/post", "headers": { - "User-Agent": "funplugin/${GetVersion()}", + "User-Agent": "funplugin/${get_version()}", "Content-Type": "text/plain" }, "body": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." @@ -102,7 +102,7 @@ "method": "POST", "url": "/post", "headers": { - "User-Agent": "funplugin/${GetVersion()}", + "User-Agent": "funplugin/${get_version()}", "Content-Type": "application/x-www-form-urlencoded" }, "body": "foo1=$foo1&foo2=$foo2&foo3=$foo3" diff --git a/examples/demo-with-go-plugin/testcases/requests.yml b/examples/demo-with-go-plugin/testcases/requests.yml index add3a28d..034dbefb 100644 --- a/examples/demo-with-go-plugin/testcases/requests.yml +++ b/examples/demo-with-go-plugin/testcases/requests.yml @@ -14,7 +14,7 @@ teststeps: variables: foo1: ${ENV(USERNAME)} foo2: bar21 - sum_v: "${SumTwoInt(1, 2)}" + sum_v: "${sum_two_int(1, 2)}" request: method: GET url: $base_url/get @@ -23,7 +23,7 @@ teststeps: foo2: $foo2 sum_v: $sum_v headers: - User-Agent: funplugin/${GetVersion()} + User-Agent: funplugin/${get_version()} extract: foo3: "body.args.foo2" validate: @@ -40,7 +40,7 @@ teststeps: method: POST url: $base_url/post headers: - User-Agent: funplugin/${GetVersion()} + User-Agent: funplugin/${get_version()} Content-Type: "text/plain" body: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." validate: @@ -54,7 +54,7 @@ teststeps: method: POST url: $base_url/post headers: - User-Agent: funplugin/${GetVersion()} + User-Agent: funplugin/${get_version()} Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo2&foo3=$foo3" validate: diff --git a/examples/demo-with-no-fungo/.gitignore b/examples/demo-with-no-fungo/.gitignore deleted file mode 100644 index 33401380..00000000 --- a/examples/demo-with-no-fungo/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -.env -reports/ -*.so -.vscode/ -.idea/ -.DS_Store -output/ -__pycache__/ -*.pyc -.python-version -logs/ - -# plugin -debugtalk.bin -debugtalk.so diff --git a/examples/demo-with-no-fungo/har/.keep b/examples/demo-with-no-fungo/har/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/examples/demo-with-no-fungo/testcases/demo.json b/examples/demo-with-no-fungo/testcases/demo.json deleted file mode 100644 index a127d26d..00000000 --- a/examples/demo-with-no-fungo/testcases/demo.json +++ /dev/null @@ -1,176 +0,0 @@ -{ - "config": { - "name": "demo with complex mechanisms", - "base_url": "https://postman-echo.com", - "variables": { - "a": "${Sum(10, 2.3)}", - "b": 3.45, - "n": "${SumInts(1, 2, 2)}", - "varFoo1": "${GenRandomString($n)}", - "varFoo2": "${Max($a, $b)}" - } - }, - "teststeps": [ - { - "name": "transaction 1 start", - "transaction": { - "name": "tran1", - "type": "start" - } - }, - { - "name": "get with params", - "request": { - "method": "GET", - "url": "/get", - "params": { - "foo1": "$varFoo1", - "foo2": "$varFoo2" - }, - "headers": { - "User-Agent": "HttpRunnerPlus" - } - }, - "variables": { - "b": 34.5, - "n": 3, - "name": "get with params", - "varFoo2": "${Max($a, $b)}" - }, - "setup_hooks": [ - "${SetupHookExample($name)}" - ], - "teardown_hooks": [ - "${TeardownHookExample($name)}" - ], - "extract": { - "varFoo1": "body.args.foo1" - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "check response status code" - }, - { - "check": "headers.\"Content-Type\"", - "assert": "startswith", - "expect": "application/json" - }, - { - "check": "body.args.foo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "$varFoo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "body.args.foo2", - "assert": "equals", - "expect": "34.5", - "msg": "check args foo2" - } - ] - }, - { - "name": "transaction 1 end", - "transaction": { - "name": "tran1", - "type": "end" - } - }, - { - "name": "post json data", - "request": { - "method": "POST", - "url": "/post", - "body": { - "foo1": "$varFoo1", - "foo2": "${Max($a, $b)}" - } - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "check status code" - }, - { - "check": "body.json.foo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "body.json.foo2", - "assert": "equals", - "expect": 12.3, - "msg": "check args foo2" - } - ] - }, - { - "name": "post form data", - "request": { - "method": "POST", - "url": "/post", - "headers": { - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" - }, - "body": { - "foo1": "$varFoo1", - "foo2": "${Max($a, $b)}", - "time": "${GetTimestamp()}" - } - }, - "extract": { - "varTime": "body.form.time" - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "check status code" - }, - { - "check": "body.form.foo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "body.form.foo2", - "assert": "equals", - "expect": "12.3", - "msg": "check args foo2" - } - ] - }, - { - "name": "get with timestamp", - "request": { - "method": "GET", - "url": "/get", - "params": { - "time": "$varTime" - } - }, - "validate": [ - { - "check": "body.args.time", - "assert": "length_equals", - "expect": 13, - "msg": "check extracted var timestamp" - } - ] - } - ] -} \ No newline at end of file diff --git a/examples/demo-with-no-fungo/testcases/ref_testcase.yml b/examples/demo-with-no-fungo/testcases/ref_testcase.yml deleted file mode 100644 index 957dbdd4..00000000 --- a/examples/demo-with-no-fungo/testcases/ref_testcase.yml +++ /dev/null @@ -1,33 +0,0 @@ -config: - name: "request methods testcase: reference testcase" - variables: - foo1: testsuite_config_bar1 - expect_foo1: testsuite_config_bar1 - expect_foo2: config_bar2 - base_url: "https://postman-echo.com" - verify: False - -teststeps: -- - name: request with functions - variables: - foo1: testcase_ref_bar1 - expect_foo1: testcase_ref_bar1 - testcase: testcases/requests.yml - export: - - foo3 -- - name: post form data - variables: - foo1: bar1 - request: - method: POST - url: /post - headers: - User-Agent: funplugin/${GetVersion()} - Content-Type: "application/x-www-form-urlencoded" - data: "foo1=$foo1&foo2=$foo3" - validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "bar1"] - - eq: ["body.form.foo2", "bar21"] diff --git a/examples/demo-with-no-fungo/testcases/requests.json b/examples/demo-with-no-fungo/testcases/requests.json deleted file mode 100644 index f54e6340..00000000 --- a/examples/demo-with-no-fungo/testcases/requests.json +++ /dev/null @@ -1,138 +0,0 @@ -{ - "config": { - "name": "request methods testcase with functions", - "variables": { - "foo1": "config_bar1", - "foo2": "config_bar2", - "expect_foo1": "config_bar1", - "expect_foo2": "config_bar2" - }, - "base_url": "https://postman-echo.com", - "verify": false, - "export": [ - "foo3" - ] - }, - "teststeps": [ - { - "name": "get with params", - "variables": { - "foo1": "bar11", - "foo2": "bar21", - "sum_v": "${SumTwoInt(1, 2)}" - }, - "request": { - "method": "GET", - "url": "/get", - "params": { - "foo1": "$foo1", - "foo2": "$foo2", - "sum_v": "$sum_v" - }, - "headers": { - "User-Agent": "funplugin/${GetVersion()}" - } - }, - "extract": { - "foo3": "body.args.foo2" - }, - "validate": [ - { - "eq": [ - "status_code", - 200 - ] - }, - { - "eq": [ - "body.args.foo1", - "bar11" - ] - }, - { - "eq": [ - "body.args.sum_v", - "3" - ] - }, - { - "eq": [ - "body.args.foo2", - "bar21" - ] - } - ] - }, - { - "name": "post raw text", - "variables": { - "foo1": "bar12", - "foo3": "bar32" - }, - "request": { - "method": "POST", - "url": "/post", - "headers": { - "User-Agent": "funplugin/${GetVersion()}", - "Content-Type": "text/plain" - }, - "data": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." - }, - "validate": [ - { - "eq": [ - "status_code", - 200 - ] - }, - { - "eq": [ - "body.data", - "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32." - ] - } - ] - }, - { - "name": "post form data", - "variables": { - "foo2": "bar23" - }, - "request": { - "method": "POST", - "url": "/post", - "headers": { - "User-Agent": "funplugin/${GetVersion()}", - "Content-Type": "application/x-www-form-urlencoded" - }, - "data": "foo1=$foo1&foo2=$foo2&foo3=$foo3" - }, - "validate": [ - { - "eq": [ - "status_code", - 200 - ] - }, - { - "eq": [ - "body.form.foo1", - "$expect_foo1" - ] - }, - { - "eq": [ - "body.form.foo2", - "bar23" - ] - }, - { - "eq": [ - "body.form.foo3", - "bar21" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/examples/demo-with-no-fungo/testcases/requests.yml b/examples/demo-with-no-fungo/testcases/requests.yml deleted file mode 100644 index 7884588f..00000000 --- a/examples/demo-with-no-fungo/testcases/requests.yml +++ /dev/null @@ -1,65 +0,0 @@ -config: - name: "request methods testcase with functions" - variables: - foo1: config_bar1 - foo2: config_bar2 - expect_foo1: config_bar1 - expect_foo2: config_bar2 - base_url: "https://postman-echo.com" - verify: False - export: ["foo3"] - -teststeps: -- - name: get with params - variables: - foo1: bar11 - foo2: bar21 - sum_v: "${SumTwoInt(1, 2)}" - request: - method: GET - url: /get - params: - foo1: $foo1 - foo2: $foo2 - sum_v: $sum_v - headers: - User-Agent: funplugin/${GetVersion()} - extract: - foo3: "body.args.foo2" - validate: - - eq: ["status_code", 200] - - eq: ["body.args.foo1", "bar11"] - - eq: ["body.args.sum_v", "3"] - - eq: ["body.args.foo2", "bar21"] -- - name: post raw text - variables: - foo1: "bar12" - foo3: "bar32" - request: - method: POST - url: /post - headers: - User-Agent: funplugin/${GetVersion()} - Content-Type: "text/plain" - data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." - validate: - - eq: ["status_code", 200] - - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."] -- - name: post form data - variables: - foo2: bar23 - request: - method: POST - url: /post - headers: - User-Agent: funplugin/${GetVersion()} - Content-Type: "application/x-www-form-urlencoded" - data: "foo1=$foo1&foo2=$foo2&foo3=$foo3" - validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "$expect_foo1"] - - eq: ["body.form.foo2", "bar23"] - - eq: ["body.form.foo3", "bar21"] diff --git a/examples/demo-with-no-funppy/.gitignore b/examples/demo-with-no-funppy/.gitignore deleted file mode 100644 index 33401380..00000000 --- a/examples/demo-with-no-funppy/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -.env -reports/ -*.so -.vscode/ -.idea/ -.DS_Store -output/ -__pycache__/ -*.pyc -.python-version -logs/ - -# plugin -debugtalk.bin -debugtalk.so diff --git a/examples/demo-with-no-funppy/har/.keep b/examples/demo-with-no-funppy/har/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/examples/demo-with-no-funppy/testcases/demo.json b/examples/demo-with-no-funppy/testcases/demo.json deleted file mode 100644 index 1bb63ed8..00000000 --- a/examples/demo-with-no-funppy/testcases/demo.json +++ /dev/null @@ -1,176 +0,0 @@ -{ - "config": { - "name": "demo with complex mechanisms", - "base_url": "https://postman-echo.com", - "variables": { - "a": "${sum(10, 2.3)}", - "b": 3.45, - "n": "${sum_ints(1, 2, 2)}", - "varFoo1": "${gen_random_string($n)}", - "varFoo2": "${max($a, $b)}" - } - }, - "teststeps": [ - { - "name": "transaction 1 start", - "transaction": { - "name": "tran1", - "type": "start" - } - }, - { - "name": "get with params", - "request": { - "method": "GET", - "url": "/get", - "params": { - "foo1": "$varFoo1", - "foo2": "$varFoo2" - }, - "headers": { - "User-Agent": "HttpRunnerPlus" - } - }, - "variables": { - "b": 34.5, - "n": 3, - "name": "get with params", - "varFoo2": "${max($a, $b)}" - }, - "setup_hooks": [ - "${setup_hook_example($name)}" - ], - "teardown_hooks": [ - "${teardown_hook_example($name)}" - ], - "extract": { - "varFoo1": "body.args.foo1" - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "check response status code" - }, - { - "check": "headers.\"Content-Type\"", - "assert": "startswith", - "expect": "application/json" - }, - { - "check": "body.args.foo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "$varFoo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "body.args.foo2", - "assert": "equals", - "expect": "34.5", - "msg": "check args foo2" - } - ] - }, - { - "name": "transaction 1 end", - "transaction": { - "name": "tran1", - "type": "end" - } - }, - { - "name": "post json data", - "request": { - "method": "POST", - "url": "/post", - "body": { - "foo1": "$varFoo1", - "foo2": "${max($a, $b)}" - } - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "check status code" - }, - { - "check": "body.json.foo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "body.json.foo2", - "assert": "equals", - "expect": 12.3, - "msg": "check args foo2" - } - ] - }, - { - "name": "post form data", - "request": { - "method": "POST", - "url": "/post", - "headers": { - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" - }, - "body": { - "foo1": "$varFoo1", - "foo2": "${max($a, $b)}", - "time": "${get_timestamp()}" - } - }, - "extract": { - "varTime": "body.form.time" - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "check status code" - }, - { - "check": "body.form.foo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "body.form.foo2", - "assert": "equals", - "expect": "12.3", - "msg": "check args foo2" - } - ] - }, - { - "name": "get with timestamp", - "request": { - "method": "GET", - "url": "/get", - "params": { - "time": "$varTime" - } - }, - "validate": [ - { - "check": "body.args.time", - "assert": "length_equals", - "expect": 13, - "msg": "check extracted var timestamp" - } - ] - } - ] -} \ No newline at end of file diff --git a/examples/demo-with-no-funppy/testcases/ref_testcase.yml b/examples/demo-with-no-funppy/testcases/ref_testcase.yml deleted file mode 100644 index 6cf32323..00000000 --- a/examples/demo-with-no-funppy/testcases/ref_testcase.yml +++ /dev/null @@ -1,33 +0,0 @@ -config: - name: "request methods testcase: reference testcase" - variables: - foo1: testsuite_config_bar1 - expect_foo1: testsuite_config_bar1 - expect_foo2: config_bar2 - base_url: "https://postman-echo.com" - verify: False - -teststeps: -- - name: request with functions - variables: - foo1: testcase_ref_bar1 - expect_foo1: testcase_ref_bar1 - testcase: testcases/requests.yml - export: - - foo3 -- - name: post form data - variables: - foo1: bar1 - request: - method: POST - url: /post - headers: - User-Agent: funplugin/${get_version()} - Content-Type: "application/x-www-form-urlencoded" - data: "foo1=$foo1&foo2=$foo3" - validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "bar1"] - - eq: ["body.form.foo2", "bar21"] diff --git a/examples/demo-with-no-funppy/testcases/requests.json b/examples/demo-with-no-funppy/testcases/requests.json deleted file mode 100644 index b13f3837..00000000 --- a/examples/demo-with-no-funppy/testcases/requests.json +++ /dev/null @@ -1,138 +0,0 @@ -{ - "config": { - "name": "request methods testcase with functions", - "variables": { - "foo1": "config_bar1", - "foo2": "config_bar2", - "expect_foo1": "config_bar1", - "expect_foo2": "config_bar2" - }, - "base_url": "https://postman-echo.com", - "verify": false, - "export": [ - "foo3" - ] - }, - "teststeps": [ - { - "name": "get with params", - "variables": { - "foo1": "bar11", - "foo2": "bar21", - "sum_v": "${sum_two_int(1, 2)}" - }, - "request": { - "method": "GET", - "url": "/get", - "params": { - "foo1": "$foo1", - "foo2": "$foo2", - "sum_v": "$sum_v" - }, - "headers": { - "User-Agent": "funplugin/${get_version()}" - } - }, - "extract": { - "foo3": "body.args.foo2" - }, - "validate": [ - { - "eq": [ - "status_code", - 200 - ] - }, - { - "eq": [ - "body.args.foo1", - "bar11" - ] - }, - { - "eq": [ - "body.args.sum_v", - "3" - ] - }, - { - "eq": [ - "body.args.foo2", - "bar21" - ] - } - ] - }, - { - "name": "post raw text", - "variables": { - "foo1": "bar12", - "foo3": "bar32" - }, - "request": { - "method": "POST", - "url": "/post", - "headers": { - "User-Agent": "funplugin/${get_version()}", - "Content-Type": "text/plain" - }, - "data": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." - }, - "validate": [ - { - "eq": [ - "status_code", - 200 - ] - }, - { - "eq": [ - "body.data", - "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32." - ] - } - ] - }, - { - "name": "post form data", - "variables": { - "foo2": "bar23" - }, - "request": { - "method": "POST", - "url": "/post", - "headers": { - "User-Agent": "funplugin/${get_version()}", - "Content-Type": "application/x-www-form-urlencoded" - }, - "data": "foo1=$foo1&foo2=$foo2&foo3=$foo3" - }, - "validate": [ - { - "eq": [ - "status_code", - 200 - ] - }, - { - "eq": [ - "body.form.foo1", - "$expect_foo1" - ] - }, - { - "eq": [ - "body.form.foo2", - "bar23" - ] - }, - { - "eq": [ - "body.form.foo3", - "bar21" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/examples/demo-with-no-funppy/testcases/requests.yml b/examples/demo-with-no-funppy/testcases/requests.yml deleted file mode 100644 index 86d1b9cc..00000000 --- a/examples/demo-with-no-funppy/testcases/requests.yml +++ /dev/null @@ -1,65 +0,0 @@ -config: - name: "request methods testcase with functions" - variables: - foo1: config_bar1 - foo2: config_bar2 - expect_foo1: config_bar1 - expect_foo2: config_bar2 - base_url: "https://postman-echo.com" - verify: False - export: ["foo3"] - -teststeps: -- - name: get with params - variables: - foo1: bar11 - foo2: bar21 - sum_v: "${sum_two_int(1, 2)}" - request: - method: GET - url: /get - params: - foo1: $foo1 - foo2: $foo2 - sum_v: $sum_v - headers: - User-Agent: funplugin/${get_version()} - extract: - foo3: "body.args.foo2" - validate: - - eq: ["status_code", 200] - - eq: ["body.args.foo1", "bar11"] - - eq: ["body.args.sum_v", "3"] - - eq: ["body.args.foo2", "bar21"] -- - name: post raw text - variables: - foo1: "bar12" - foo3: "bar32" - request: - method: POST - url: /post - headers: - User-Agent: funplugin/${get_version()} - Content-Type: "text/plain" - data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." - validate: - - eq: ["status_code", 200] - - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."] -- - name: post form data - variables: - foo2: bar23 - request: - method: POST - url: /post - headers: - User-Agent: funplugin/${get_version()} - Content-Type: "application/x-www-form-urlencoded" - data: "foo1=$foo1&foo2=$foo2&foo3=$foo3" - validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "$expect_foo1"] - - eq: ["body.form.foo2", "bar23"] - - eq: ["body.form.foo3", "bar21"] diff --git a/examples/demo-with-py-plugin/proj.json b/examples/demo-with-py-plugin/proj.json index 555bccd7..9d8cce0e 100644 --- a/examples/demo-with-py-plugin/proj.json +++ b/examples/demo-with-py-plugin/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-with-py-plugin", "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-py-plugin", - "create_time": "2022-05-27T11:34:31.852589+08:00", + "create_time": "2022-05-28T02:00:28.517914+08:00", "hrp_version": "v4.1.0-beta" } \ No newline at end of file diff --git a/examples/demo-without-plugin/proj.json b/examples/demo-without-plugin/proj.json index 72c78cbf..e622b2a7 100644 --- a/examples/demo-without-plugin/proj.json +++ b/examples/demo-without-plugin/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-without-plugin", "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-without-plugin", - "create_time": "2022-05-27T11:34:32.548637+08:00", + "create_time": "2022-05-28T02:00:29.191678+08:00", "hrp_version": "v4.1.0-beta" } \ No newline at end of file diff --git a/go.mod b/go.mod index 857c9444..080c56a0 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/go-openapi/spec v0.20.6 github.com/google/uuid v1.3.0 github.com/gorilla/websocket v1.4.1 - github.com/httprunner/funplugin v0.4.6 + github.com/httprunner/funplugin v0.4.7 github.com/jinzhu/copier v0.3.2 github.com/jmespath/go-jmespath v0.4.0 github.com/json-iterator/go v1.1.12 diff --git a/go.sum b/go.sum index 4651a6e7..921c4995 100644 --- a/go.sum +++ b/go.sum @@ -253,8 +253,8 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/httprunner/funplugin v0.4.6 h1:wwpjzo3G9a5BCXBkHs845w4ifKaCtVa/yQjREQjQOgo= -github.com/httprunner/funplugin v0.4.6/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc= +github.com/httprunner/funplugin v0.4.7 h1:bmk84BL8oPGE/rgxCuHgPcwJtBnwDzm/ocmFY/cKcos= +github.com/httprunner/funplugin v0.4.7/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= diff --git a/hrp/boomer_test.go b/hrp/boomer_test.go index b70fc832..4edefa38 100644 --- a/hrp/boomer_test.go +++ b/hrp/boomer_test.go @@ -25,7 +25,7 @@ func TestBoomerStandaloneRun(t *testing.T) { NewStep("TestCase3").CallRefCase(&TestCase{Config: NewConfig("TestCase3")}), }, } - testcase2 := &demoTestCaseWithGoPluginJSONPath + testcase2 := &demoTestCaseWithPluginJSONPath b := NewBoomer(2, 1) go b.Run(testcase1, testcase2) diff --git a/hrp/internal/build/main.go b/hrp/internal/build/main.go index 39c2e92a..2c9cd28b 100644 --- a/hrp/internal/build/main.go +++ b/hrp/internal/build/main.go @@ -23,10 +23,10 @@ const ( funppy = `import funppy` fungo = `"github.com/httprunner/funplugin/fungo"` regexPythonFunctionName = `def ([a-zA-Z_]\w*)\(.*\)` - regexGoImports = `import\s*\(\n([\s\S]*)\n\)` - regexGoImport = `import\s*(\"[\s\S]*\")\n` + regexGoImports = `import \(([\s\S]*?)\)` + regexGoImport = `import (\"[\s\S]*\")` regexGoFunctionName = `func ([A-Z][a-zA-Z_]\w*)\(.*\)` - regexGoFunctionContent = `func [\s\S]*?\n}\n` + regexGoFunctionContent = `func [\s\S]*?\n}` ) //go:embed templates/debugtalkPythonTemplate diff --git a/hrp/internal/build/main_test.go b/hrp/internal/build/main_test.go index b26109a2..41eb1489 100644 --- a/hrp/internal/build/main_test.go +++ b/hrp/internal/build/main_test.go @@ -1,30 +1,21 @@ package build import ( - "github.com/httprunner/httprunner/v4/hrp/internal/builtin" "regexp" "testing" + "github.com/httprunner/httprunner/v4/hrp/internal/builtin" + "github.com/stretchr/testify/assert" ) func TestRun(t *testing.T) { - err := Run("../../../examples/demo-with-no-fungo/plugin/debugtalk.go", "") + err := Run("plugin/debugtalk.go", "./debugtalk_gen.bin") if !assert.Nil(t, err) { t.Fatal() } - err = Run("../../../examples/demo-with-no-funppy/debugtalk.py", "") - if !assert.Nil(t, err) { - t.Fatal() - } - - err = Run("../../../examples/demo-with-no-fungo/plugin/debugtalk.go", "./debugtalk_gen.bin") - if !assert.Nil(t, err) { - t.Fatal() - } - - err = Run("../../../examples/demo-with-no-funppy/debugtalk.py", "./debugtalk_gen.py") + err = Run("plugin/debugtalk.py", "./debugtalk_gen.py") if !assert.Nil(t, err) { t.Fatal() } diff --git a/examples/demo-with-no-fungo/plugin/debugtalk.go b/hrp/internal/build/plugin/debugtalk.go similarity index 91% rename from examples/demo-with-no-fungo/plugin/debugtalk.go rename to hrp/internal/build/plugin/debugtalk.go index 5810e0e4..eb189472 100644 --- a/examples/demo-with-no-fungo/plugin/debugtalk.go +++ b/hrp/internal/build/plugin/debugtalk.go @@ -1,13 +1,9 @@ -package main +package noplugin import ( "fmt" ) -func init() { - fmt.Println("init") -} - func SumTwoInt(a, b int) int { return a + b } @@ -42,3 +38,7 @@ func SetupHookExample(args string) string { func TeardownHookExample(args string) string { return fmt.Sprintf("step name: %v, teardown...", args) } + +func GetVersion() string { + return "v0.4" +} diff --git a/examples/demo-with-no-funppy/debugtalk.py b/hrp/internal/build/plugin/debugtalk.py similarity index 96% rename from examples/demo-with-no-funppy/debugtalk.py rename to hrp/internal/build/plugin/debugtalk.py index 8d93ae1f..9f4c52bc 100644 --- a/examples/demo-with-no-funppy/debugtalk.py +++ b/hrp/internal/build/plugin/debugtalk.py @@ -4,7 +4,7 @@ from typing import List def get_version(): - return "httprunner v4.0" + return "v0.4" def sleep(n_secs): diff --git a/hrp/internal/scaffold/templates/plugin/debugtalk.go b/hrp/internal/scaffold/templates/plugin/debugtalk.go index 3995ea24..b3b39400 100644 --- a/hrp/internal/scaffold/templates/plugin/debugtalk.go +++ b/hrp/internal/scaffold/templates/plugin/debugtalk.go @@ -46,12 +46,12 @@ func GetVersion() string { } func main() { - fungo.Register("GetVersion", GetVersion) - fungo.Register("SumInts", SumInts) - fungo.Register("SumTwoInt", SumTwoInt) - fungo.Register("SumTwoInt", SumTwoInt) - fungo.Register("Sum", Sum) - fungo.Register("SetupHookExample", SetupHookExample) - fungo.Register("TeardownHookExample", TeardownHookExample) + fungo.Register("get_version", GetVersion) + fungo.Register("sum_ints", SumInts) + fungo.Register("sum_two_int", SumTwoInt) + fungo.Register("sum_two", SumTwoInt) + fungo.Register("sum", Sum) + fungo.Register("setup_hook_example", SetupHookExample) + fungo.Register("teardown_hook_example", TeardownHookExample) fungo.Serve() } diff --git a/hrp/internal/scaffold/templates/testcases/demo_go_ref_testcase.yml b/hrp/internal/scaffold/templates/testcases/demo_go_ref_testcase.yml deleted file mode 100644 index 957dbdd4..00000000 --- a/hrp/internal/scaffold/templates/testcases/demo_go_ref_testcase.yml +++ /dev/null @@ -1,33 +0,0 @@ -config: - name: "request methods testcase: reference testcase" - variables: - foo1: testsuite_config_bar1 - expect_foo1: testsuite_config_bar1 - expect_foo2: config_bar2 - base_url: "https://postman-echo.com" - verify: False - -teststeps: -- - name: request with functions - variables: - foo1: testcase_ref_bar1 - expect_foo1: testcase_ref_bar1 - testcase: testcases/requests.yml - export: - - foo3 -- - name: post form data - variables: - foo1: bar1 - request: - method: POST - url: /post - headers: - User-Agent: funplugin/${GetVersion()} - Content-Type: "application/x-www-form-urlencoded" - data: "foo1=$foo1&foo2=$foo3" - validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "bar1"] - - eq: ["body.form.foo2", "bar21"] diff --git a/hrp/internal/scaffold/templates/testcases/demo_go_requests.json b/hrp/internal/scaffold/templates/testcases/demo_go_requests.json deleted file mode 100644 index f54e6340..00000000 --- a/hrp/internal/scaffold/templates/testcases/demo_go_requests.json +++ /dev/null @@ -1,138 +0,0 @@ -{ - "config": { - "name": "request methods testcase with functions", - "variables": { - "foo1": "config_bar1", - "foo2": "config_bar2", - "expect_foo1": "config_bar1", - "expect_foo2": "config_bar2" - }, - "base_url": "https://postman-echo.com", - "verify": false, - "export": [ - "foo3" - ] - }, - "teststeps": [ - { - "name": "get with params", - "variables": { - "foo1": "bar11", - "foo2": "bar21", - "sum_v": "${SumTwoInt(1, 2)}" - }, - "request": { - "method": "GET", - "url": "/get", - "params": { - "foo1": "$foo1", - "foo2": "$foo2", - "sum_v": "$sum_v" - }, - "headers": { - "User-Agent": "funplugin/${GetVersion()}" - } - }, - "extract": { - "foo3": "body.args.foo2" - }, - "validate": [ - { - "eq": [ - "status_code", - 200 - ] - }, - { - "eq": [ - "body.args.foo1", - "bar11" - ] - }, - { - "eq": [ - "body.args.sum_v", - "3" - ] - }, - { - "eq": [ - "body.args.foo2", - "bar21" - ] - } - ] - }, - { - "name": "post raw text", - "variables": { - "foo1": "bar12", - "foo3": "bar32" - }, - "request": { - "method": "POST", - "url": "/post", - "headers": { - "User-Agent": "funplugin/${GetVersion()}", - "Content-Type": "text/plain" - }, - "data": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." - }, - "validate": [ - { - "eq": [ - "status_code", - 200 - ] - }, - { - "eq": [ - "body.data", - "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32." - ] - } - ] - }, - { - "name": "post form data", - "variables": { - "foo2": "bar23" - }, - "request": { - "method": "POST", - "url": "/post", - "headers": { - "User-Agent": "funplugin/${GetVersion()}", - "Content-Type": "application/x-www-form-urlencoded" - }, - "data": "foo1=$foo1&foo2=$foo2&foo3=$foo3" - }, - "validate": [ - { - "eq": [ - "status_code", - 200 - ] - }, - { - "eq": [ - "body.form.foo1", - "$expect_foo1" - ] - }, - { - "eq": [ - "body.form.foo2", - "bar23" - ] - }, - { - "eq": [ - "body.form.foo3", - "bar21" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/hrp/internal/scaffold/templates/testcases/demo_go_requests.yml b/hrp/internal/scaffold/templates/testcases/demo_go_requests.yml deleted file mode 100644 index 7884588f..00000000 --- a/hrp/internal/scaffold/templates/testcases/demo_go_requests.yml +++ /dev/null @@ -1,65 +0,0 @@ -config: - name: "request methods testcase with functions" - variables: - foo1: config_bar1 - foo2: config_bar2 - expect_foo1: config_bar1 - expect_foo2: config_bar2 - base_url: "https://postman-echo.com" - verify: False - export: ["foo3"] - -teststeps: -- - name: get with params - variables: - foo1: bar11 - foo2: bar21 - sum_v: "${SumTwoInt(1, 2)}" - request: - method: GET - url: /get - params: - foo1: $foo1 - foo2: $foo2 - sum_v: $sum_v - headers: - User-Agent: funplugin/${GetVersion()} - extract: - foo3: "body.args.foo2" - validate: - - eq: ["status_code", 200] - - eq: ["body.args.foo1", "bar11"] - - eq: ["body.args.sum_v", "3"] - - eq: ["body.args.foo2", "bar21"] -- - name: post raw text - variables: - foo1: "bar12" - foo3: "bar32" - request: - method: POST - url: /post - headers: - User-Agent: funplugin/${GetVersion()} - Content-Type: "text/plain" - data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." - validate: - - eq: ["status_code", 200] - - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."] -- - name: post form data - variables: - foo2: bar23 - request: - method: POST - url: /post - headers: - User-Agent: funplugin/${GetVersion()} - Content-Type: "application/x-www-form-urlencoded" - data: "foo1=$foo1&foo2=$foo2&foo3=$foo3" - validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "$expect_foo1"] - - eq: ["body.form.foo2", "bar23"] - - eq: ["body.form.foo3", "bar21"] diff --git a/hrp/internal/scaffold/templates/testcases/demo_go_with_funplugin.json b/hrp/internal/scaffold/templates/testcases/demo_go_with_funplugin.json deleted file mode 100644 index 0af40519..00000000 --- a/hrp/internal/scaffold/templates/testcases/demo_go_with_funplugin.json +++ /dev/null @@ -1,176 +0,0 @@ -{ - "config": { - "name": "demo with complex mechanisms", - "base_url": "https://postman-echo.com", - "variables": { - "a": "${Sum(10, 2.3)}", - "b": 3.45, - "n": "${SumInts(1, 2, 2)}", - "varFoo1": "${gen_random_string($n)}", - "varFoo2": "${max($a, $b)}" - } - }, - "teststeps": [ - { - "name": "transaction 1 start", - "transaction": { - "name": "tran1", - "type": "start" - } - }, - { - "name": "get with params", - "request": { - "method": "GET", - "url": "/get", - "params": { - "foo1": "$varFoo1", - "foo2": "$varFoo2" - }, - "headers": { - "User-Agent": "HttpRunnerPlus" - } - }, - "variables": { - "b": 34.5, - "n": 3, - "name": "get with params", - "varFoo2": "${max($a, $b)}" - }, - "setup_hooks": [ - "${SetupHookExample($name)}" - ], - "teardown_hooks": [ - "${TeardownHookExample($name)}" - ], - "extract": { - "varFoo1": "body.args.foo1" - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "check response status code" - }, - { - "check": "headers.\"Content-Type\"", - "assert": "startswith", - "expect": "application/json" - }, - { - "check": "body.args.foo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "$varFoo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "body.args.foo2", - "assert": "equals", - "expect": "34.5", - "msg": "check args foo2" - } - ] - }, - { - "name": "transaction 1 end", - "transaction": { - "name": "tran1", - "type": "end" - } - }, - { - "name": "post json data", - "request": { - "method": "POST", - "url": "/post", - "body": { - "foo1": "$varFoo1", - "foo2": "${max($a, $b)}" - } - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "check status code" - }, - { - "check": "body.json.foo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "body.json.foo2", - "assert": "equals", - "expect": 12.3, - "msg": "check args foo2" - } - ] - }, - { - "name": "post form data", - "request": { - "method": "POST", - "url": "/post", - "headers": { - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" - }, - "body": { - "foo1": "$varFoo1", - "foo2": "${max($a, $b)}", - "time": "${get_timestamp()}" - } - }, - "extract": { - "varTime": "body.form.time" - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "check status code" - }, - { - "check": "body.form.foo1", - "assert": "length_equals", - "expect": 5, - "msg": "check args foo1" - }, - { - "check": "body.form.foo2", - "assert": "equals", - "expect": "12.3", - "msg": "check args foo2" - } - ] - }, - { - "name": "get with timestamp", - "request": { - "method": "GET", - "url": "/get", - "params": { - "time": "$varTime" - } - }, - "validate": [ - { - "check": "body.args.time", - "assert": "length_equals", - "expect": 13, - "msg": "check extracted var timestamp" - } - ] - } - ] -} \ No newline at end of file diff --git a/hrp/parser.go b/hrp/parser.go index b9693f0d..84482e3a 100644 --- a/hrp/parser.go +++ b/hrp/parser.go @@ -252,8 +252,14 @@ func (p *Parser) ParseString(raw string, variablesMapping map[string]interface{} // only support return at most one result value func (p *Parser) CallFunc(funcName string, arguments ...interface{}) (interface{}, error) { // call with plugin function - if p.plugin != nil && p.plugin.Has(funcName) { - return p.plugin.Call(funcName, arguments...) + if p.plugin != nil { + if p.plugin.Has(funcName) { + return p.plugin.Call(funcName, arguments...) + } + commonName := shared.ConvertCommonName(funcName) + if p.plugin.Has(commonName) { + return p.plugin.Call(commonName, arguments...) + } } // get builtin function diff --git a/hrp/plugin.go b/hrp/plugin.go index 72d6767d..eeeda537 100644 --- a/hrp/plugin.go +++ b/hrp/plugin.go @@ -2,7 +2,6 @@ package hrp import ( "fmt" - "github.com/httprunner/httprunner/v4/hrp/internal/build" "os" "os/signal" "path/filepath" @@ -12,6 +11,7 @@ import ( "github.com/httprunner/funplugin" "github.com/rs/zerolog/log" + "github.com/httprunner/httprunner/v4/hrp/internal/build" "github.com/httprunner/httprunner/v4/hrp/internal/sdk" ) @@ -20,6 +20,7 @@ const ( hashicorpGoPluginFile = "debugtalk.bin" // built from hashicorp go plugin hashicorpPyPluginFile = "debugtalk_gen.py" // used for hashicorp python plugin, automatically generated by HRP debugtalkPyFile = "debugtalk.py" // write by user + projectInfoFile = "proj.json" // used for ensuring root project ) func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir string, err error) { diff --git a/hrp/runner_test.go b/hrp/runner_test.go index 4c043090..5a1327e2 100644 --- a/hrp/runner_test.go +++ b/hrp/runner_test.go @@ -12,18 +12,9 @@ import ( "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 := build.Run(templatesDir+"noplugin/debugtalk.go", templatesDir+"debugtalk.bin") + err := build.Run(templatesDir+"plugin/debugtalk.go", templatesDir+"debugtalk.bin") if err != nil { log.Error().Err(err).Msg("build hashicorp go plugin failed") os.Exit(1) @@ -38,7 +29,7 @@ func removeHashicorpGoPlugin() { func buildHashicorpPyPlugin() { log.Info().Msg("[init] prepare hashicorp python plugin") pluginFile := templatesDir + "debugtalk.py" - err := scaffold.CopyFile("templates/noplugin/debugtalk.py", pluginFile) + err := scaffold.CopyFile("templates/plugin/debugtalk.py", pluginFile) if err != nil { log.Error().Err(err).Msg("build hashicorp python plugin failed") os.Exit(1) @@ -55,6 +46,17 @@ 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"), @@ -81,7 +83,7 @@ func TestRunCaseWithGoPlugin(t *testing.T) { }, }, ), - NewStep("testcase1-step4").CallRefCase(&demoTestCaseWithGoPluginJSONPath), + NewStep("testcase1-step4").CallRefCase(&demoTestCaseWithPluginJSONPath), }, } testcase2 := &TestCase{ @@ -96,18 +98,6 @@ func TestRunCaseWithGoPlugin(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() @@ -170,15 +160,15 @@ func TestRunCaseWithPluginJSON(t *testing.T) { buildHashicorpGoPlugin() defer removeHashicorpGoPlugin() - err := NewRunner(nil).Run(&demoTestCaseWithGoPluginJSONPath) // hrp.Run(testCase) + err := NewRunner(nil).Run(&demoTestCaseWithPluginJSONPath) // hrp.Run(testCase) if err != nil { t.Fatal() } } func TestRunCaseWithPluginYAML(t *testing.T) { - buildHashicorpPyPlugin() - defer removeHashicorpPyPlugin() + buildHashicorpGoPlugin() + defer removeHashicorpGoPlugin() err := NewRunner(nil).Run(&demoTestCaseWithPluginYAMLPath) // hrp.Run(testCase) if err != nil { diff --git a/hrp/testcase_test.go b/hrp/testcase_test.go index 6564612e..eb6a69ae 100644 --- a/hrp/testcase_test.go +++ b/hrp/testcase_test.go @@ -15,7 +15,6 @@ const ( var ( demoTestCaseWithPluginJSONPath TestCasePath = templatesDir + "testcases/demo_with_funplugin.json" - demoTestCaseWithGoPluginJSONPath TestCasePath = templatesDir + "testcases/demo_go_with_funplugin.json" demoTestCaseWithPluginYAMLPath TestCasePath = templatesDir + "testcases/demo_with_funplugin.yaml" demoTestCaseWithoutPluginJSONPath TestCasePath = templatesDir + "testcases/demo_without_funplugin.json" demoTestCaseWithoutPluginYAMLPath TestCasePath = templatesDir + "testcases/demo_without_funplugin.yaml"