mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-20 23:59:49 +08:00
feat: support api layer and global headers for testcase
This commit is contained in:
@@ -16,6 +16,9 @@ type Boomer struct {
|
||||
|
||||
memoryProfile string
|
||||
memoryProfileDuration time.Duration
|
||||
|
||||
disableKeepalive bool
|
||||
disableCompression bool
|
||||
}
|
||||
|
||||
// NewStandaloneBoomer returns a new Boomer, which can run without master.
|
||||
@@ -52,6 +55,24 @@ func (b *Boomer) SetRateLimiter(maxRPS int64, requestIncreaseRate string) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetDisableKeepAlive disable keep-alive for tcp
|
||||
func (b *Boomer) SetDisableKeepAlive(disableKeepalive bool) {
|
||||
b.disableKeepalive = disableKeepalive
|
||||
}
|
||||
|
||||
// SetDisableCompression disable compression to prevent the Transport from requesting compression with an "Accept-Encoding: gzip"
|
||||
func (b *Boomer) SetDisableCompression(disableCompression bool) {
|
||||
b.disableCompression = disableCompression
|
||||
}
|
||||
|
||||
func (b *Boomer) GetDisableKeepAlive() bool {
|
||||
return b.disableKeepalive
|
||||
}
|
||||
|
||||
func (b *Boomer) GetDisableCompression() bool {
|
||||
return b.disableCompression
|
||||
}
|
||||
|
||||
// SetLoopCount set loop count for test.
|
||||
func (b *Boomer) SetLoopCount(loopCount int64) {
|
||||
b.localRunner.loop = &Loop{loopCount: loopCount}
|
||||
|
||||
@@ -255,6 +255,10 @@ func deserializeStatsEntry(stat interface{}) (entryOutput *statsEntryOutput, err
|
||||
var duration float64
|
||||
if entry.Name == "Total" {
|
||||
duration = float64(entry.LastRequestTimestamp - entry.StartTime)
|
||||
// fix: avoid divide by zero
|
||||
if duration < 1 {
|
||||
duration = 1
|
||||
}
|
||||
} else {
|
||||
duration = float64(reportStatsInterval / time.Second)
|
||||
}
|
||||
|
||||
@@ -211,3 +211,12 @@ func EnsureFolderExists(folderPath string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Contains(s []string, e string) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -12,4 +12,5 @@ var (
|
||||
MarshalIndent = json.MarshalIndent
|
||||
Unmarshal = json.Unmarshal
|
||||
NewDecoder = json.NewDecoder
|
||||
Get = json.Get
|
||||
)
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
demoTestCaseJSONPath = "../../examples/demo.json"
|
||||
demoTestCaseYAMLPath = "../../examples/demo.yaml"
|
||||
demoTestCaseJSONPath hrp.TestCasePath = "../../examples/demo.json"
|
||||
demoTestCaseYAMLPath hrp.TestCasePath = "../../examples/demo.yaml"
|
||||
)
|
||||
|
||||
func buildHashicorpPlugin() {
|
||||
@@ -33,11 +33,11 @@ func removeHashicorpPlugin() {
|
||||
|
||||
func TestGenDemoTestCase(t *testing.T) {
|
||||
tCase, _ := demoTestCase.ToTCase()
|
||||
err := builtin.Dump2JSON(tCase, demoTestCaseJSONPath)
|
||||
err := builtin.Dump2JSON(tCase, demoTestCaseJSONPath.ToString())
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
err = builtin.Dump2YAML(tCase, demoTestCaseYAMLPath)
|
||||
err = builtin.Dump2YAML(tCase, demoTestCaseYAMLPath.ToString())
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
@@ -58,8 +58,7 @@ func TestJsonDemo(t *testing.T) {
|
||||
buildHashicorpPlugin()
|
||||
defer removeHashicorpPlugin()
|
||||
|
||||
testCase := &hrp.TestCasePath{Path: demoTestCaseJSONPath}
|
||||
err := hrp.NewRunner(nil).Run(testCase) // hrp.Run(testCase)
|
||||
err := hrp.NewRunner(nil).Run(&demoTestCaseJSONPath) // hrp.Run(testCase)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
@@ -69,8 +68,7 @@ func TestYamlDemo(t *testing.T) {
|
||||
buildHashicorpPlugin()
|
||||
defer removeHashicorpPlugin()
|
||||
|
||||
testCase := &hrp.TestCasePath{Path: demoTestCaseYAMLPath}
|
||||
err := hrp.NewRunner(nil).Run(testCase) // hrp.Run(testCase)
|
||||
err := hrp.NewRunner(nil).Run(&demoTestCaseYAMLPath) // hrp.Run(testCase)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user