mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-15 20:38:44 +08:00
refactor: NewConfig
This commit is contained in:
@@ -8,17 +8,15 @@ import (
|
||||
)
|
||||
|
||||
var demoTestCase = &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "demo with complex mechanisms",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Variables: map[string]interface{}{ // global level variables
|
||||
Config: hrp.NewConfig("demo with complex mechanisms").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
WithVariables(map[string]interface{}{ // global level variables
|
||||
"n": 5,
|
||||
"a": 12.3,
|
||||
"b": 3.45,
|
||||
"varFoo1": "${gen_random_string($n)}",
|
||||
"varFoo2": "${max($a, $b)}", // 12.3; eval with built-in function
|
||||
},
|
||||
},
|
||||
}),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
WithVariables(map[string]interface{}{ // step level variables
|
||||
|
||||
@@ -9,11 +9,9 @@ import (
|
||||
// reference extracted variables for validation in the same step
|
||||
func TestCaseExtractStepSingle(t *testing.T) {
|
||||
testcase := &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "run request with variables",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Verify: false,
|
||||
},
|
||||
Config: hrp.NewConfig("run request with variables").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
SetVerifySSL(false),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
WithVariables(map[string]interface{}{
|
||||
@@ -46,11 +44,9 @@ func TestCaseExtractStepSingle(t *testing.T) {
|
||||
// reference extracted variables from previous step
|
||||
func TestCaseExtractStepAssociation(t *testing.T) {
|
||||
testcase := &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "run request with variables",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Verify: false,
|
||||
},
|
||||
Config: hrp.NewConfig("run request with variables").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
SetVerifySSL(false),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
WithVariables(map[string]interface{}{
|
||||
|
||||
@@ -8,16 +8,14 @@ import (
|
||||
|
||||
func TestCaseCallFunction(t *testing.T) {
|
||||
testcase := &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "run request with functions",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Verify: false,
|
||||
Variables: map[string]interface{}{
|
||||
Config: hrp.NewConfig("run request with functions").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
WithVariables(map[string]interface{}{
|
||||
"n": 5,
|
||||
"a": 12.3,
|
||||
"b": 3.45,
|
||||
},
|
||||
},
|
||||
}).
|
||||
SetVerifySSL(false),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
GET("/get").
|
||||
|
||||
@@ -8,11 +8,9 @@ import (
|
||||
|
||||
func TestCaseBasicRequest(t *testing.T) {
|
||||
testcase := &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "request methods testcase in hardcode",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Verify: false,
|
||||
},
|
||||
Config: hrp.NewConfig("request methods testcase in hardcode").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
SetVerifySSL(false),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
GET("/get").
|
||||
|
||||
@@ -8,11 +8,9 @@ import (
|
||||
|
||||
func TestCaseValidateStep(t *testing.T) {
|
||||
testcase := &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "run request with validation",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Verify: false,
|
||||
},
|
||||
Config: hrp.NewConfig("run request with validation").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
SetVerifySSL(false),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
WithVariables(map[string]interface{}{
|
||||
|
||||
@@ -8,16 +8,13 @@ import (
|
||||
|
||||
func TestCaseConfigVariables(t *testing.T) {
|
||||
testcase := &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "run request with variables",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Variables: map[string]interface{}{
|
||||
Config: hrp.NewConfig("run request with variables").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
WithVariables(map[string]interface{}{
|
||||
"var1": "bar1",
|
||||
"agent": "HttpRunnerPlus",
|
||||
"expectedStatusCode": 200,
|
||||
},
|
||||
Verify: false,
|
||||
},
|
||||
}).SetVerifySSL(false),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
GET("/get").
|
||||
@@ -41,11 +38,9 @@ func TestCaseConfigVariables(t *testing.T) {
|
||||
|
||||
func TestCaseStepVariables(t *testing.T) {
|
||||
testcase := &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "run request with variables",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Verify: false,
|
||||
},
|
||||
Config: hrp.NewConfig("run request with variables").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
SetVerifySSL(false),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
WithVariables(map[string]interface{}{
|
||||
@@ -74,16 +69,13 @@ func TestCaseStepVariables(t *testing.T) {
|
||||
|
||||
func TestCaseOverrideConfigVariables(t *testing.T) {
|
||||
testcase := &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "run request with variables",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Variables: map[string]interface{}{
|
||||
Config: hrp.NewConfig("run request with variables").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
WithVariables(map[string]interface{}{
|
||||
"var1": "bar0",
|
||||
"agent": "HttpRunnerPlus",
|
||||
"expectedStatusCode": 200,
|
||||
},
|
||||
Verify: false,
|
||||
},
|
||||
}).SetVerifySSL(false),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
WithVariables(map[string]interface{}{
|
||||
@@ -112,18 +104,15 @@ func TestCaseOverrideConfigVariables(t *testing.T) {
|
||||
|
||||
func TestCaseParseVariables(t *testing.T) {
|
||||
testcase := &hrp.TestCase{
|
||||
Config: hrp.TConfig{
|
||||
Name: "run request with functions",
|
||||
BaseURL: "https://postman-echo.com",
|
||||
Verify: false,
|
||||
Variables: map[string]interface{}{
|
||||
Config: hrp.NewConfig("run request with functions").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
WithVariables(map[string]interface{}{
|
||||
"n": 5,
|
||||
"a": 12.3,
|
||||
"b": 3.45,
|
||||
"varFoo1": "${gen_random_string($n)}",
|
||||
"varFoo2": "${max($a, $b)}", // 12.3
|
||||
},
|
||||
},
|
||||
}).SetVerifySSL(false),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("get with params").
|
||||
WithVariables(map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user