fix: unittests

This commit is contained in:
lilong.129
2023-07-22 11:40:16 +08:00
parent c712aa425e
commit e212ccf0b9
8 changed files with 18 additions and 36 deletions

View File

@@ -64,11 +64,6 @@ jobs:
- 1.18.x
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
services:
service-httpbin:
image: kennethreitz/httpbin
ports:
- 80:80
steps:
- name: Install Go
uses: actions/setup-go@v2

View File

@@ -71,11 +71,6 @@ jobs:
- 1.18.x
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
services:
service-httpbin:
image: kennethreitz/httpbin
ports:
- 80:80
steps:
- name: Install Go
uses: actions/setup-go@v2

View File

@@ -10,7 +10,7 @@ func TestBoomerStandaloneRun(t *testing.T) {
defer removeHashicorpGoPlugin()
testcase1 := &TestCase{
Config: NewConfig("TestCase1").SetBaseURL(HTTP_BIN_URL),
Config: NewConfig("TestCase1").SetBaseURL("https://postman-echo.com"),
TestSteps: []IStep{
NewStep("headers").
GET("/headers").

View File

@@ -7,12 +7,11 @@ import (
"testing"
"time"
"github.com/httprunner/httprunner/v4/hrp/internal/code"
"github.com/rs/zerolog/log"
"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() {
log.Info().Msg("[init] build hashicorp go plugin")
@@ -65,31 +64,26 @@ func assertRunTestCases(t *testing.T) {
refCase := TestCasePath(demoTestCaseWithPluginJSONPath)
testcase1 := &TestCase{
Config: NewConfig("TestCase1").
SetBaseURL(HTTP_BIN_URL),
SetBaseURL("https://postman-echo.com"),
TestSteps: []IStep{
NewStep("testcase1-step1").
GET("/headers").
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("headers.\"Content-Type\"", "application/json", "check http response Content-Type"),
NewStep("testcase1-step2").
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(
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check http response Content-Type"),
NewStep("testcase1-step2").CallRefCase(
&TestCase{
Config: NewConfig("testcase1-step3-ref-case").SetBaseURL(HTTP_BIN_URL),
Config: NewConfig("testcase1-step3-ref-case").SetBaseURL("https://postman-echo.com"),
TestSteps: []IStep{
NewStep("ip").
GET("/ip").
Validate().
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{

View File

@@ -165,7 +165,7 @@ func TestRunCaseWithTimeout(t *testing.T) {
testcase1 := &TestCase{
Config: NewConfig("TestCase1").
SetRequestTimeout(10). // set global timeout to 10s
SetBaseURL(HTTP_BIN_URL),
SetBaseURL("https://postman-echo.com"),
TestSteps: []IStep{
NewStep("step1").
GET("/delay/1").
@@ -181,7 +181,7 @@ func TestRunCaseWithTimeout(t *testing.T) {
testcase2 := &TestCase{
Config: NewConfig("TestCase2").
SetRequestTimeout(10). // set global timeout to 10s
SetBaseURL(HTTP_BIN_URL),
SetBaseURL("https://postman-echo.com"),
TestSteps: []IStep{
NewStep("step1").
GET("/delay/11").
@@ -198,7 +198,7 @@ func TestRunCaseWithTimeout(t *testing.T) {
testcase3 := &TestCase{
Config: NewConfig("TestCase3").
SetRequestTimeout(10).
SetBaseURL(HTTP_BIN_URL),
SetBaseURL("https://postman-echo.com"),
TestSteps: []IStep{
NewStep("step2").
GET("/delay/11").

View File

@@ -6,12 +6,10 @@ import (
"github.com/httprunner/httprunner/v4/hrp"
)
const HTTP_BIN_URL = "http://127.0.0.1:80"
func TestCaseUploadFile(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.NewConfig("test upload file to httpbin").
SetBaseURL(HTTP_BIN_URL).
SetBaseURL("https://httpbin.org").
WithVariables(map[string]interface{}{"upload_file": "test.env"}),
TestSteps: []hrp.IStep{
hrp.NewStep("upload file explicitly").

View File

@@ -17,7 +17,7 @@ class TestHttpSession(unittest.TestCase):
self.assertGreater(address.client_port, 10000)
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
self.assertGreater(len(address.server_ip), 0)
self.assertEqual(address.server_port, 443)
@@ -39,7 +39,7 @@ class TestHttpSession(unittest.TestCase):
def test_request_https_allow_redirects(self):
self.session.request(
"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,
)
address = self.session.data.address
@@ -63,7 +63,7 @@ class TestHttpSession(unittest.TestCase):
def test_request_https_not_allow_redirects(self):
self.session.request(
"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,
)
address = self.session.data.address

View File

@@ -121,10 +121,10 @@ class TestUtils(unittest.TestCase):
def test_override_config_variables(self):
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(
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):