Apply goimports' modifications
This commit is contained in:
parent
2bb6c45786
commit
113b90531c
@ -37,4 +37,3 @@ func TestConvertParams(t *testing.T) {
|
|||||||
}, reflect.TypeOf(Demo), ctx)
|
}, reflect.TypeOf(Demo), ctx)
|
||||||
assert.Equal(t, int64(11), res[0].Int())
|
assert.Equal(t, int64(11), res[0].Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ type User struct {
|
|||||||
type Seller struct {
|
type Seller struct {
|
||||||
Id int
|
Id int
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRegisterModelWithPrefix(t *testing.T) {
|
func TestRegisterModelWithPrefix(t *testing.T) {
|
||||||
RegisterModelWithPrefix("test", &User{}, &Seller{})
|
RegisterModelWithPrefix("test", &User{}, &Seller{})
|
||||||
}
|
}
|
||||||
|
|||||||
4
client/cache/calc_utils_test.go
vendored
4
client/cache/calc_utils_test.go
vendored
@ -19,7 +19,7 @@ func TestIncr(t *testing.T) {
|
|||||||
t.Errorf("incr failed, expect %v, but %v actually", updateVal, val)
|
t.Errorf("incr failed, expect %v, but %v actually", updateVal, val)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = incr(int(1 << (strconv.IntSize - 1) - 1))
|
_, err = incr(int(1<<(strconv.IntSize-1) - 1))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("incr failed")
|
t.Error("incr failed")
|
||||||
return
|
return
|
||||||
@ -73,7 +73,7 @@ func TestIncr(t *testing.T) {
|
|||||||
t.Errorf("incr failed, expect %v, but %v actually", updateVal, val)
|
t.Errorf("incr failed, expect %v, but %v actually", updateVal, val)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = incr(uint(1 << (strconv.IntSize) - 1))
|
_, err = incr(uint(1<<(strconv.IntSize) - 1))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("incr failed")
|
t.Error("incr failed")
|
||||||
return
|
return
|
||||||
|
|||||||
@ -51,7 +51,6 @@ Sometimes you got JSON document and you want to make it as request body. So you
|
|||||||
If you do this, you got this code. Instead, you should call Header to set Content-type and call Body to set body data.
|
If you do this, you got this code. Instead, you should call Header to set Content-type and call Body to set body data.
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
|
||||||
// start with 5 --------------------------------------------------------------------------
|
// start with 5 --------------------------------------------------------------------------
|
||||||
|
|
||||||
var CreateFormFileFailed = berror.DefineCode(5001001, moduleName, "CreateFormFileFailed", `
|
var CreateFormFileFailed = berror.DefineCode(5001001, moduleName, "CreateFormFileFailed", `
|
||||||
@ -125,7 +124,3 @@ Make sure that:
|
|||||||
1. You pass valid structure pointer to the function;
|
1. You pass valid structure pointer to the function;
|
||||||
2. The body is valid YAML document
|
2. The body is valid YAML document
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestNewHttpResponseWithJsonBody(t *testing.T) {
|
func TestNewHttpResponseWithJsonBody(t *testing.T) {
|
||||||
// string
|
// string
|
||||||
resp := NewHttpResponseWithJsonBody("{}")
|
resp := NewHttpResponseWithJsonBody("{}")
|
||||||
|
|||||||
@ -309,7 +309,6 @@ func TestFilterChainOrder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
req.AddFilters(func(next Filter) Filter {
|
req.AddFilters(func(next Filter) Filter {
|
||||||
return func(ctx context.Context, req *BeegoHTTPRequest) (*http.Response, error) {
|
return func(ctx context.Context, req *BeegoHTTPRequest) (*http.Response, error) {
|
||||||
return NewHttpResponseWithJsonBody("second"), nil
|
return NewHttpResponseWithJsonBody("second"), nil
|
||||||
@ -419,10 +418,10 @@ func TestBeegoHTTPRequest_Body(t *testing.T) {
|
|||||||
req.Body(13)
|
req.Body(13)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type user struct {
|
type user struct {
|
||||||
Name string `xml:"name"`
|
Name string `xml:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBeegoHTTPRequest_XMLBody(t *testing.T) {
|
func TestBeegoHTTPRequest_XMLBody(t *testing.T) {
|
||||||
req := Post("http://beego.me")
|
req := Post("http://beego.me")
|
||||||
body := &user{
|
body := &user{
|
||||||
|
|||||||
@ -44,7 +44,7 @@ func StartMock() Stub {
|
|||||||
return mockFilter
|
return mockFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
func CtxWithMock(ctx context.Context, mock... *Mock) context.Context {
|
func CtxWithMock(ctx context.Context, mock ...*Mock) context.Context {
|
||||||
return context.WithValue(ctx, mockCtxKey, mock)
|
return context.WithValue(ctx, mockCtxKey, mock)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,5 +76,3 @@ func NewMock(con RequestCondition, resp *http.Response, err error) *Mock {
|
|||||||
err: err,
|
err: err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -120,7 +120,6 @@ func (sc *SimpleCondition) matchBodyFields(ctx context.Context, req *httplib.Bee
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
|
|
||||||
err = json.Unmarshal(bytes, &m)
|
err = json.Unmarshal(bytes, &m)
|
||||||
|
|||||||
@ -72,6 +72,6 @@ func OriginnalCodeUsingHttplibPassCtx(ctx context.Context) (*http.Response, erro
|
|||||||
return httplib.Get("http://localhost:7777/abc").DoRequestWithCtx(ctx)
|
return httplib.Get("http://localhost:7777/abc").DoRequestWithCtx(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OriginalCodeUsingHttplib() (*http.Response, error){
|
func OriginalCodeUsingHttplib() (*http.Response, error) {
|
||||||
return httplib.Get("http://localhost:7777/abc").DoRequest()
|
return httplib.Get("http://localhost:7777/abc").DoRequest()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
package order_clause
|
package order_clause
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/beego/beego/v2/client/orm/clauses"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/client/orm/clauses"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Sort int8
|
type Sort int8
|
||||||
|
|||||||
@ -16,10 +16,11 @@ package orm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beego/beego/v2/client/orm/clauses"
|
|
||||||
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/client/orm/clauses"
|
||||||
|
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
||||||
)
|
)
|
||||||
|
|
||||||
// table info struct.
|
// table info struct.
|
||||||
|
|||||||
@ -24,7 +24,9 @@ import (
|
|||||||
|
|
||||||
"github.com/beego/beego/v2/client/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
const mockErrorMsg = "mock error"
|
const mockErrorMsg = "mock error"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
orm.RegisterModel(&User{})
|
orm.RegisterModel(&User{})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import (
|
|||||||
// DoNothingQueryM2Mer do nothing
|
// DoNothingQueryM2Mer do nothing
|
||||||
// use it to build mock orm.QueryM2Mer
|
// use it to build mock orm.QueryM2Mer
|
||||||
type DoNothingQueryM2Mer struct {
|
type DoNothingQueryM2Mer struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DoNothingQueryM2Mer) AddWithCtx(ctx context.Context, i ...interface{}) (int64, error) {
|
func (d *DoNothingQueryM2Mer) AddWithCtx(ctx context.Context, i ...interface{}) (int64, error) {
|
||||||
@ -88,5 +87,3 @@ func (q *QueryM2MerCondition) Match(ctx context.Context, inv *orm.Invocation) bo
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -58,11 +58,12 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/client/orm/hints"
|
"github.com/beego/beego/v2/client/orm/hints"
|
||||||
"github.com/beego/beego/v2/core/utils"
|
"github.com/beego/beego/v2/core/utils"
|
||||||
|
|
||||||
|
|||||||
@ -16,8 +16,9 @@ package orm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beego/beego/v2/client/orm/clauses"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/client/orm/clauses"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExprSep define the expression separation
|
// ExprSep define the expression separation
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
@ -32,6 +31,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/client/orm/hints"
|
"github.com/beego/beego/v2/client/orm/hints"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|||||||
@ -19,8 +19,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// A Code is an unsigned 32-bit error code as defined in the beego spec.
|
// A Code is an unsigned 32-bit error code as defined in the beego spec.
|
||||||
type Code interface {
|
type Code interface {
|
||||||
Code() uint32
|
Code() uint32
|
||||||
@ -57,7 +55,6 @@ type codeRegistry struct {
|
|||||||
codes map[uint32]*codeDefinition
|
codes map[uint32]*codeDefinition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (cr *codeRegistry) Get(code uint32) (Code, bool) {
|
func (cr *codeRegistry) Get(code uint32) (Code, bool) {
|
||||||
cr.lock.RLock()
|
cr.lock.RLock()
|
||||||
defer cr.lock.RUnlock()
|
defer cr.lock.RUnlock()
|
||||||
@ -72,7 +69,6 @@ type codeDefinition struct {
|
|||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *codeDefinition) Name() string {
|
func (c *codeDefinition) Name() string {
|
||||||
return c.name
|
return c.name
|
||||||
}
|
}
|
||||||
@ -88,4 +84,3 @@ func (c *codeDefinition) Module() string {
|
|||||||
func (c *codeDefinition) Desc() string {
|
func (c *codeDefinition) Desc() string {
|
||||||
return c.desc
|
return c.desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import (
|
|||||||
// pre define code
|
// pre define code
|
||||||
|
|
||||||
// Unknown indicates got some error which is not defined
|
// Unknown indicates got some error which is not defined
|
||||||
var Unknown = DefineCode(5000001, "error", "Unknown",fmt.Sprintf(`
|
var Unknown = DefineCode(5000001, "error", "Unknown", fmt.Sprintf(`
|
||||||
Unknown error code. Usually you will see this code in three cases:
|
Unknown error code. Usually you will see this code in three cases:
|
||||||
1. You forget to define Code or function DefineCode not being executed;
|
1. You forget to define Code or function DefineCode not being executed;
|
||||||
2. This is not Beego's error but you call FromError();
|
2. This is not Beego's error but you call FromError();
|
||||||
@ -49,4 +49,3 @@ func goCodeBlock(code string) string {
|
|||||||
func codeBlock(lan string, code string) string {
|
func codeBlock(lan string, code string) string {
|
||||||
return fmt.Sprintf("```%s\n%s\n```", lan, code)
|
return fmt.Sprintf("```%s\n%s\n```", lan, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,10 +15,11 @@
|
|||||||
package context
|
package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestXsrfReset_01(t *testing.T) {
|
func TestXsrfReset_01(t *testing.T) {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package session
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
webContext "github.com/beego/beego/v2/server/web/context"
|
webContext "github.com/beego/beego/v2/server/web/context"
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
package session
|
package session
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
webContext "github.com/beego/beego/v2/server/web/context"
|
webContext "github.com/beego/beego/v2/server/web/context"
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func testRequest(t *testing.T, handler *web.ControllerRegister, path string, method string, code int) {
|
func testRequest(t *testing.T, handler *web.ControllerRegister, path string, method string, code int) {
|
||||||
|
|||||||
@ -60,7 +60,6 @@ func TestControllerRegister_InsertFilterChain_Order(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
InsertFilterChain("/abc", func(next FilterFunc) FilterFunc {
|
InsertFilterChain("/abc", func(next FilterFunc) FilterFunc {
|
||||||
return func(ctx *context.Context) {
|
return func(ctx *context.Context) {
|
||||||
ctx.Output.Header("second", fmt.Sprintf("%d", time.Now().UnixNano()))
|
ctx.Output.Header("second", fmt.Sprintf("%d", time.Now().UnixNano()))
|
||||||
|
|||||||
@ -342,7 +342,7 @@ func (t *Tree) match(treePattern string, pattern string, wildcardValues []string
|
|||||||
if runObject == nil && len(t.fixrouters) > 0 {
|
if runObject == nil && len(t.fixrouters) > 0 {
|
||||||
// Filter the .json .xml .html extension
|
// Filter the .json .xml .html extension
|
||||||
for _, str := range allowSuffixExt {
|
for _, str := range allowSuffixExt {
|
||||||
if strings.HasSuffix(seg, str) && strings.HasSuffix(treePattern, seg){
|
if strings.HasSuffix(seg, str) && strings.HasSuffix(treePattern, seg) {
|
||||||
for _, subTree := range t.fixrouters {
|
for _, subTree := range t.fixrouters {
|
||||||
// strings.HasSuffix(treePattern, seg) avoid cases: /aaa.html/bbb could access /aaa/bbb
|
// strings.HasSuffix(treePattern, seg) avoid cases: /aaa.html/bbb could access /aaa/bbb
|
||||||
if subTree.prefix == seg[:len(seg)-len(str)] {
|
if subTree.prefix == seg[:len(seg)-len(str)] {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user