feat: support to reuse the cookies (#301)
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
This commit is contained in:
parent
1bc6b66520
commit
19da5cdc32
12
cmd/run.go
12
cmd/run.go
|
@ -320,6 +320,11 @@ func (o *runOption) runSuite(loader testing.Loader, dataContext map[string]inter
|
|||
return
|
||||
}
|
||||
|
||||
suiteRunner := runner.GetTestSuiteRunner(testSuite)
|
||||
suiteRunner.WithTestReporter(o.reporter)
|
||||
suiteRunner.WithSecure(testSuite.Spec.Secure)
|
||||
suiteRunner.WithOutputWriter(os.Stdout)
|
||||
suiteRunner.WithWriteLevel(o.level)
|
||||
for _, testCase := range testSuite.Items {
|
||||
if !testCase.InScope(o.caseItems) {
|
||||
continue
|
||||
|
@ -338,12 +343,7 @@ func (o *runOption) runSuite(loader testing.Loader, dataContext map[string]inter
|
|||
ctxWithTimeout, _ := context.WithTimeout(ctx, o.requestTimeout)
|
||||
ctxWithTimeout = context.WithValue(ctxWithTimeout, runner.ContextKey("").ParentDir(), loader.GetContext())
|
||||
|
||||
runner := runner.GetTestSuiteRunner(testSuite)
|
||||
runner.WithTestReporter(o.reporter)
|
||||
runner.WithSecure(testSuite.Spec.Secure)
|
||||
runner.WithOutputWriter(os.Stdout)
|
||||
runner.WithWriteLevel(o.level)
|
||||
if output, err = runner.RunTestCase(&testCase, dataContext, ctxWithTimeout); err != nil && !o.requestIgnoreError {
|
||||
if output, err = suiteRunner.RunTestCase(&testCase, dataContext, ctxWithTimeout); err != nil && !o.requestIgnoreError {
|
||||
err = fmt.Errorf("failed to run '%s', %v", testCase.Name, err)
|
||||
return
|
||||
} else {
|
||||
|
|
|
@ -78,6 +78,7 @@ func (r ReportResultSlice) Swap(i, j int) {
|
|||
type simpleTestCaseRunner struct {
|
||||
UnimplementedRunner
|
||||
simpleResponse SimpleResponse
|
||||
cookies []*http.Cookie
|
||||
}
|
||||
|
||||
// NewSimpleTestCaseRunner creates the instance of the simple test case runner
|
||||
|
@ -85,6 +86,7 @@ func NewSimpleTestCaseRunner() TestCaseRunner {
|
|||
runner := &simpleTestCaseRunner{
|
||||
UnimplementedRunner: NewDefaultUnimplementedRunner(),
|
||||
simpleResponse: SimpleResponse{},
|
||||
cookies: []*http.Cookie{},
|
||||
}
|
||||
return runner
|
||||
}
|
||||
|
@ -155,6 +157,9 @@ func (r *simpleTestCaseRunner) RunTestCase(testcase *testing.TestCase, dataConte
|
|||
return
|
||||
}
|
||||
|
||||
for _, cookie := range r.cookies {
|
||||
request.AddCookie(cookie)
|
||||
}
|
||||
r.log.Info("start to send request to %s\n", testcase.Request.API)
|
||||
|
||||
// TODO only do this for unit testing, should remove it once we have a better way
|
||||
|
@ -203,6 +208,8 @@ func (r *simpleTestCaseRunner) RunTestCase(testcase *testing.TestCase, dataConte
|
|||
} else {
|
||||
r.log.Trace(fmt.Sprintf("skip to read the body due to it is not struct content: %q\n", respType))
|
||||
}
|
||||
|
||||
r.cookies = append(r.cookies, resp.Cookies()...)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue