Merge pull request #4652 from Loyalsoldier/httplib-fix-lint
Fix lint and format code in client/httplib dir
This commit is contained in:
commit
b420b064d2
@ -5,6 +5,7 @@
|
|||||||
- Infra: use dependabot to update dependencies. [4623](https://github.com/beego/beego/pull/4623)
|
- Infra: use dependabot to update dependencies. [4623](https://github.com/beego/beego/pull/4623)
|
||||||
- Lint: use golangci-lint. [4619](https://github.com/beego/beego/pull/4619)
|
- Lint: use golangci-lint. [4619](https://github.com/beego/beego/pull/4619)
|
||||||
- Chore: format code. [4615](https://github.com/beego/beego/pull/4615)
|
- Chore: format code. [4615](https://github.com/beego/beego/pull/4615)
|
||||||
|
- Fix lint and format code in client/httplib dir [4652](https://github.com/beego/beego/pull/4652)
|
||||||
- Test on Go v1.15.x & v1.16.x. [4614](https://github.com/beego/beego/pull/4614)
|
- Test on Go v1.15.x & v1.16.x. [4614](https://github.com/beego/beego/pull/4614)
|
||||||
- Env: non-empty GOBIN & GOPATH. [4613](https://github.com/beego/beego/pull/4613)
|
- Env: non-empty GOBIN & GOPATH. [4613](https://github.com/beego/beego/pull/4613)
|
||||||
- Fix lint and format code in client/orm dir [4653](https://github.com/beego/beego/pull/4653)
|
- Fix lint and format code in client/orm dir [4653](https://github.com/beego/beego/pull/4653)
|
||||||
|
|||||||
@ -35,9 +35,7 @@ type FilterChainBuilder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filter {
|
func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filter {
|
||||||
|
|
||||||
return func(ctx context.Context, req *httplib.BeegoHTTPRequest) (*http.Response, error) {
|
return func(ctx context.Context, req *httplib.BeegoHTTPRequest) (*http.Response, error) {
|
||||||
|
|
||||||
method := req.GetRequest().Method
|
method := req.GetRequest().Method
|
||||||
|
|
||||||
operationName := method + "#" + req.GetRequest().URL.String()
|
operationName := method + "#" + req.GetRequest().URL.String()
|
||||||
|
|||||||
@ -32,11 +32,12 @@ type FilterChainBuilder struct {
|
|||||||
RunMode string
|
RunMode string
|
||||||
}
|
}
|
||||||
|
|
||||||
var summaryVec prometheus.ObserverVec
|
var (
|
||||||
var initSummaryVec sync.Once
|
summaryVec prometheus.ObserverVec
|
||||||
|
initSummaryVec sync.Once
|
||||||
|
)
|
||||||
|
|
||||||
func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filter {
|
func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filter {
|
||||||
|
|
||||||
initSummaryVec.Do(func() {
|
initSummaryVec.Do(func() {
|
||||||
summaryVec = prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
summaryVec = prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
||||||
Name: "beego",
|
Name: "beego",
|
||||||
|
|||||||
@ -400,7 +400,6 @@ func (b *BeegoHTTPRequest) handleFileToBody(bodyWriter *multipart.Writer, formna
|
|||||||
"could not create form file, formname: %s, filename: %s", formname, filename))
|
"could not create form file, formname: %s, filename: %s", formname, filename))
|
||||||
}
|
}
|
||||||
fh, err := os.Open(filename)
|
fh, err := os.Open(filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error(errFmt, berror.Wrapf(err, ReadFileFailed, "could not open this file %s", filename))
|
logs.Error(errFmt, berror.Wrapf(err, ReadFileFailed, "could not open this file %s", filename))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,6 @@ func TestDoRequest(t *testing.T) {
|
|||||||
if elapsedTime < delayedTime {
|
if elapsedTime < delayedTime {
|
||||||
t.Errorf("Not enough retries. Took %dms. Delay was meant to take %dms", elapsedTime, delayedTime)
|
t.Errorf("Not enough retries. Took %dms. Delay was meant to take %dms", elapsedTime, delayedTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
@ -248,7 +247,6 @@ func TestToJson(t *testing.T) {
|
|||||||
t.Fatal("response is not valid ip")
|
t.Fatal("response is not valid ip")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToFile(t *testing.T) {
|
func TestToFile(t *testing.T) {
|
||||||
|
|||||||
@ -23,10 +23,6 @@ import (
|
|||||||
"github.com/beego/beego/v2/client/httplib"
|
"github.com/beego/beego/v2/client/httplib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSimpleCondition_MatchPath(t *testing.T) {
|
func TestSimpleCondition_MatchPath(t *testing.T) {
|
||||||
sc := NewSimpleCondition("/abc/s")
|
sc := NewSimpleCondition("/abc/s")
|
||||||
res := sc.Match(context.Background(), httplib.Get("http://localhost:8080/abc/s"))
|
res := sc.Match(context.Background(), httplib.Get("http://localhost:8080/abc/s"))
|
||||||
@ -72,7 +68,6 @@ func TestSimpleCondition_MatchHeader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSimpleCondition_MatchBodyField(t *testing.T) {
|
func TestSimpleCondition_MatchBodyField(t *testing.T) {
|
||||||
|
|
||||||
sc := NewSimpleCondition("/abc/s")
|
sc := NewSimpleCondition("/abc/s")
|
||||||
req := httplib.Post("http://localhost:8080/abc/s")
|
req := httplib.Post("http://localhost:8080/abc/s")
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestStartMock(t *testing.T) {
|
func TestStartMock(t *testing.T) {
|
||||||
|
|
||||||
// httplib.defaultSetting.FilterChains = []httplib.FilterChain{mockFilter.FilterChain}
|
// httplib.defaultSetting.FilterChains = []httplib.FilterChain{mockFilter.FilterChain}
|
||||||
|
|
||||||
stub := StartMock()
|
stub := StartMock()
|
||||||
@ -41,7 +40,6 @@ func TestStartMock(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, expectedErr, err)
|
assert.Equal(t, expectedErr, err)
|
||||||
assert.Equal(t, expectedResp, resp)
|
assert.Equal(t, expectedResp, resp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestStartMock_Isolation Test StartMock that
|
// TestStartMock_Isolation Test StartMock that
|
||||||
|
|||||||
@ -68,8 +68,10 @@ var defaultSetting = BeegoHTTPSettings{
|
|||||||
FilterChains: make([]FilterChain, 0, 4),
|
FilterChains: make([]FilterChain, 0, 4),
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultCookieJar http.CookieJar
|
var (
|
||||||
var settingMutex sync.Mutex
|
defaultCookieJar http.CookieJar
|
||||||
|
settingMutex sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
// AddDefaultFilter add a new filter into defaultSetting
|
// AddDefaultFilter add a new filter into defaultSetting
|
||||||
// Be careful about using this method if you invoke SetDefaultSetting somewhere
|
// Be careful about using this method if you invoke SetDefaultSetting somewhere
|
||||||
|
|||||||
@ -18,8 +18,10 @@ import (
|
|||||||
"github.com/beego/beego/v2/client/httplib"
|
"github.com/beego/beego/v2/client/httplib"
|
||||||
)
|
)
|
||||||
|
|
||||||
var port = ""
|
var (
|
||||||
var baseURL = "http://localhost:"
|
port = ""
|
||||||
|
baseURL = "http://localhost:"
|
||||||
|
)
|
||||||
|
|
||||||
// TestHTTPRequest beego test request client
|
// TestHTTPRequest beego test request client
|
||||||
type TestHTTPRequest struct {
|
type TestHTTPRequest struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user