mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-21 04:22:30 +08:00
feat: support run testcases in specified folder path #1198
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@@ -148,15 +149,17 @@ func (r *HRPRunner) Run(testcases ...ITestCase) error {
|
||||
defer sdk.SendEvent(event.StartTiming("execution"))
|
||||
// record execution data to summary
|
||||
s := newOutSummary()
|
||||
for _, iTestCase := range testcases {
|
||||
testcase, err := iTestCase.ToTestCase()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("[Run] convert ITestCase interface to TestCase struct failed")
|
||||
return err
|
||||
}
|
||||
|
||||
// load all testcases
|
||||
testCases, err := loadTestCases(testcases...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, testcase := range testCases {
|
||||
cfg := testcase.Config
|
||||
// parse config parameters
|
||||
err = initParameterIterator(cfg, "runner")
|
||||
err := initParameterIterator(cfg, "runner")
|
||||
if err != nil {
|
||||
log.Error().Interface("parameters", cfg.Parameters).Err(err).Msg("parse config parameters failed")
|
||||
return err
|
||||
@@ -201,6 +204,56 @@ func (r *HRPRunner) Run(testcases ...ITestCase) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadTestCases(iTestCases ...ITestCase) ([]*TestCase, error) {
|
||||
testCases := make([]*TestCase, 0)
|
||||
|
||||
for _, iTestCase := range iTestCases {
|
||||
if _, ok := iTestCase.(*TestCase); ok {
|
||||
testcase, err := iTestCase.ToTestCase()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to convert ITestCase interface to TestCase struct")
|
||||
return nil, err
|
||||
}
|
||||
testCases = append(testCases, testcase)
|
||||
continue
|
||||
}
|
||||
|
||||
// iTestCase should be a TestCasePath, file path or folder path
|
||||
testCasePath, ok := iTestCase.(*TestCasePath)
|
||||
if !ok {
|
||||
return nil, errors.New("invalid iTestCase type")
|
||||
}
|
||||
|
||||
casePaths := make([]*TestCasePath, 0)
|
||||
casePath := iTestCase.GetPath()
|
||||
if builtin.IsFolderPathExists(casePath) {
|
||||
// folder path
|
||||
files, err := ioutil.ReadDir(casePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read dir")
|
||||
}
|
||||
for _, f := range files {
|
||||
path := TestCasePath(filepath.Join(casePath, f.Name()))
|
||||
casePaths = append(casePaths, &path)
|
||||
}
|
||||
} else {
|
||||
// file path
|
||||
casePaths = append(casePaths, testCasePath)
|
||||
}
|
||||
|
||||
for _, path := range casePaths {
|
||||
tc, err := path.ToTestCase()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
testCases = append(testCases, tc)
|
||||
}
|
||||
}
|
||||
|
||||
log.Info().Int("count", len(testCases)).Msg("load testcases successfully")
|
||||
return testCases, nil
|
||||
}
|
||||
|
||||
func (r *HRPRunner) newCaseRunner(testcase *TestCase) *caseRunner {
|
||||
caseRunner := &caseRunner{
|
||||
TestCase: testcase,
|
||||
|
||||
Reference in New Issue
Block a user