mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
fix: unittests
This commit is contained in:
5
.github/workflows/smoketest.yml
vendored
5
.github/workflows/smoketest.yml
vendored
@@ -64,11 +64,6 @@ jobs:
|
|||||||
- 1.18.x
|
- 1.18.x
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
services:
|
|
||||||
service-httpbin:
|
|
||||||
image: kennethreitz/httpbin
|
|
||||||
ports:
|
|
||||||
- 80:80
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
|
|||||||
5
.github/workflows/unittest.yml
vendored
5
.github/workflows/unittest.yml
vendored
@@ -71,11 +71,6 @@ jobs:
|
|||||||
- 1.18.x
|
- 1.18.x
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
services:
|
|
||||||
service-httpbin:
|
|
||||||
image: kennethreitz/httpbin
|
|
||||||
ports:
|
|
||||||
- 80:80
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ func TestBoomerStandaloneRun(t *testing.T) {
|
|||||||
defer removeHashicorpGoPlugin()
|
defer removeHashicorpGoPlugin()
|
||||||
|
|
||||||
testcase1 := &TestCase{
|
testcase1 := &TestCase{
|
||||||
Config: NewConfig("TestCase1").SetBaseURL(HTTP_BIN_URL),
|
Config: NewConfig("TestCase1").SetBaseURL("https://postman-echo.com"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("headers").
|
NewStep("headers").
|
||||||
GET("/headers").
|
GET("/headers").
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
|
||||||
|
|
||||||
const HTTP_BIN_URL = "http://127.0.0.1:80"
|
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||||
|
)
|
||||||
|
|
||||||
func buildHashicorpGoPlugin() {
|
func buildHashicorpGoPlugin() {
|
||||||
log.Info().Msg("[init] build hashicorp go plugin")
|
log.Info().Msg("[init] build hashicorp go plugin")
|
||||||
@@ -65,31 +64,26 @@ func assertRunTestCases(t *testing.T) {
|
|||||||
refCase := TestCasePath(demoTestCaseWithPluginJSONPath)
|
refCase := TestCasePath(demoTestCaseWithPluginJSONPath)
|
||||||
testcase1 := &TestCase{
|
testcase1 := &TestCase{
|
||||||
Config: NewConfig("TestCase1").
|
Config: NewConfig("TestCase1").
|
||||||
SetBaseURL(HTTP_BIN_URL),
|
SetBaseURL("https://postman-echo.com"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("testcase1-step1").
|
NewStep("testcase1-step1").
|
||||||
GET("/headers").
|
GET("/headers").
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", 200, "check status code").
|
AssertEqual("status_code", 200, "check status code").
|
||||||
AssertEqual("headers.\"Content-Type\"", "application/json", "check http response Content-Type"),
|
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check http response Content-Type"),
|
||||||
NewStep("testcase1-step2").
|
NewStep("testcase1-step2").CallRefCase(
|
||||||
GET("/user-agent").
|
|
||||||
Validate().
|
|
||||||
AssertEqual("status_code", 200, "check status code").
|
|
||||||
AssertEqual("headers.\"Content-Type\"", "application/json", "check http response Content-Type"),
|
|
||||||
NewStep("testcase1-step3").CallRefCase(
|
|
||||||
&TestCase{
|
&TestCase{
|
||||||
Config: NewConfig("testcase1-step3-ref-case").SetBaseURL(HTTP_BIN_URL),
|
Config: NewConfig("testcase1-step3-ref-case").SetBaseURL("https://postman-echo.com"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("ip").
|
NewStep("ip").
|
||||||
GET("/ip").
|
GET("/ip").
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", 200, "check status code").
|
AssertEqual("status_code", 200, "check status code").
|
||||||
AssertEqual("headers.\"Content-Type\"", "application/json", "check http response Content-Type"),
|
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check http response Content-Type"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
NewStep("testcase1-step4").CallRefCase(&refCase),
|
NewStep("testcase1-step3").CallRefCase(&refCase),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
testcase2 := &TestCase{
|
testcase2 := &TestCase{
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ func TestRunCaseWithTimeout(t *testing.T) {
|
|||||||
testcase1 := &TestCase{
|
testcase1 := &TestCase{
|
||||||
Config: NewConfig("TestCase1").
|
Config: NewConfig("TestCase1").
|
||||||
SetRequestTimeout(10). // set global timeout to 10s
|
SetRequestTimeout(10). // set global timeout to 10s
|
||||||
SetBaseURL(HTTP_BIN_URL),
|
SetBaseURL("https://postman-echo.com"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("step1").
|
NewStep("step1").
|
||||||
GET("/delay/1").
|
GET("/delay/1").
|
||||||
@@ -181,7 +181,7 @@ func TestRunCaseWithTimeout(t *testing.T) {
|
|||||||
testcase2 := &TestCase{
|
testcase2 := &TestCase{
|
||||||
Config: NewConfig("TestCase2").
|
Config: NewConfig("TestCase2").
|
||||||
SetRequestTimeout(10). // set global timeout to 10s
|
SetRequestTimeout(10). // set global timeout to 10s
|
||||||
SetBaseURL(HTTP_BIN_URL),
|
SetBaseURL("https://postman-echo.com"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("step1").
|
NewStep("step1").
|
||||||
GET("/delay/11").
|
GET("/delay/11").
|
||||||
@@ -198,7 +198,7 @@ func TestRunCaseWithTimeout(t *testing.T) {
|
|||||||
testcase3 := &TestCase{
|
testcase3 := &TestCase{
|
||||||
Config: NewConfig("TestCase3").
|
Config: NewConfig("TestCase3").
|
||||||
SetRequestTimeout(10).
|
SetRequestTimeout(10).
|
||||||
SetBaseURL(HTTP_BIN_URL),
|
SetBaseURL("https://postman-echo.com"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("step2").
|
NewStep("step2").
|
||||||
GET("/delay/11").
|
GET("/delay/11").
|
||||||
|
|||||||
@@ -6,12 +6,10 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v4/hrp"
|
"github.com/httprunner/httprunner/v4/hrp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const HTTP_BIN_URL = "http://127.0.0.1:80"
|
|
||||||
|
|
||||||
func TestCaseUploadFile(t *testing.T) {
|
func TestCaseUploadFile(t *testing.T) {
|
||||||
testcase := &hrp.TestCase{
|
testcase := &hrp.TestCase{
|
||||||
Config: hrp.NewConfig("test upload file to httpbin").
|
Config: hrp.NewConfig("test upload file to httpbin").
|
||||||
SetBaseURL(HTTP_BIN_URL).
|
SetBaseURL("https://httpbin.org").
|
||||||
WithVariables(map[string]interface{}{"upload_file": "test.env"}),
|
WithVariables(map[string]interface{}{"upload_file": "test.env"}),
|
||||||
TestSteps: []hrp.IStep{
|
TestSteps: []hrp.IStep{
|
||||||
hrp.NewStep("upload file explicitly").
|
hrp.NewStep("upload file explicitly").
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class TestHttpSession(unittest.TestCase):
|
|||||||
self.assertGreater(address.client_port, 10000)
|
self.assertGreater(address.client_port, 10000)
|
||||||
|
|
||||||
def test_request_https(self):
|
def test_request_https(self):
|
||||||
self.session.request("get", "https://httpbin.org/get")
|
self.session.request("get", "https://postman-echo.com/get")
|
||||||
address = self.session.data.address
|
address = self.session.data.address
|
||||||
self.assertGreater(len(address.server_ip), 0)
|
self.assertGreater(len(address.server_ip), 0)
|
||||||
self.assertEqual(address.server_port, 443)
|
self.assertEqual(address.server_port, 443)
|
||||||
@@ -39,7 +39,7 @@ class TestHttpSession(unittest.TestCase):
|
|||||||
def test_request_https_allow_redirects(self):
|
def test_request_https_allow_redirects(self):
|
||||||
self.session.request(
|
self.session.request(
|
||||||
"get",
|
"get",
|
||||||
"https://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
"https://postman-echo.com/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||||
allow_redirects=True,
|
allow_redirects=True,
|
||||||
)
|
)
|
||||||
address = self.session.data.address
|
address = self.session.data.address
|
||||||
@@ -63,7 +63,7 @@ class TestHttpSession(unittest.TestCase):
|
|||||||
def test_request_https_not_allow_redirects(self):
|
def test_request_https_not_allow_redirects(self):
|
||||||
self.session.request(
|
self.session.request(
|
||||||
"get",
|
"get",
|
||||||
"https://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
"https://postman-echo.com/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||||
allow_redirects=False,
|
allow_redirects=False,
|
||||||
)
|
)
|
||||||
address = self.session.data.address
|
address = self.session.data.address
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ class TestUtils(unittest.TestCase):
|
|||||||
|
|
||||||
def test_override_config_variables(self):
|
def test_override_config_variables(self):
|
||||||
step_variables = {"base_url": "$base_url", "foo1": "bar1"}
|
step_variables = {"base_url": "$base_url", "foo1": "bar1"}
|
||||||
config_variables = {"base_url": "https://httpbin.org", "foo1": "bar111"}
|
config_variables = {"base_url": "https://postman-echo.com", "foo1": "bar111"}
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
merge_variables(step_variables, config_variables),
|
merge_variables(step_variables, config_variables),
|
||||||
{"base_url": "https://httpbin.org", "foo1": "bar1"},
|
{"base_url": "https://postman-echo.com", "foo1": "bar1"},
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_cartesian_product_one(self):
|
def test_cartesian_product_one(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user