fix issue in ut for package gsha1/gclient/ghttp/gregex

This commit is contained in:
John Guo 2021-12-23 00:34:02 +08:00
parent 48c5c1e5a8
commit fab17f89c4
4 changed files with 12 additions and 15 deletions

View File

@ -13,7 +13,6 @@ import (
"io"
"os"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/util/gconv"
)

View File

@ -197,21 +197,19 @@ func (c *Client) prepareRequest(ctx context.Context, method, url string, data ..
formFieldName = array[0]
)
if file, err = writer.CreateFormFile(formFieldName, formFileName); err != nil {
err = gerror.Wrapf(err, `writer.CreateFormFile failed with "%s", "%s"`, formFieldName, formFileName)
err = gerror.Wrapf(err, `CreateFormFile failed with "%s", "%s"`, formFieldName, formFileName)
return nil, err
} else {
var f *os.File
if f, err = os.Open(path); err == nil {
err = gerror.Wrapf(err, `os.Open failed for name "%s"`, path)
if f, err = gfile.Open(path); err != nil {
return nil, err
} else {
if _, err = io.Copy(file, f); err != nil {
err = gerror.Wrapf(err, `io.Copy failed from "%s" to form "%s"`, path, formFieldName)
_ = f.Close()
return nil, err
}
_ = f.Close()
}
if _, err = io.Copy(file, f); err != nil {
err = gerror.Wrapf(err, `io.Copy failed from "%s" to form "%s"`, path, formFieldName)
_ = f.Close()
return nil, err
}
_ = f.Close()
}
} else {
var (
@ -219,7 +217,7 @@ func (c *Client) prepareRequest(ctx context.Context, method, url string, data ..
fieldValue = array[1]
)
if err = writer.WriteField(fieldName, fieldValue); err != nil {
err = gerror.Wrapf(err, `writer.WriteField failed with "%s", "%s"`, fieldName, fieldValue)
err = gerror.Wrapf(err, `write form field failed with "%s", "%s"`, fieldName, fieldValue)
return nil, err
}
}
@ -227,7 +225,7 @@ func (c *Client) prepareRequest(ctx context.Context, method, url string, data ..
// Close finishes the multipart message and writes the trailing
// boundary end line to the output.
if err = writer.Close(); err != nil {
err = gerror.Wrapf(err, `writer.Close failed`)
err = gerror.Wrapf(err, `form writer close failed`)
return nil, err
}

View File

@ -150,7 +150,7 @@ func Test_ClientMaxBodySize_File(t *testing.T) {
defer gfile.Remove(path)
t.Assert(
gstr.Trim(c.PostContent(ctx, "/", "name=john&file=@file:"+path)),
"Invalid Request: http: request body too large",
"r.ParseMultipartForm failed: http: request body too large",
)
})
}

View File

@ -275,5 +275,5 @@ func ExampleValidate() {
// Output:
// <nil>
// error parsing regexp: invalid character class range: `a-9`
// regexp.Compile failed for pattern "[a-9]\d+": error parsing regexp: invalid character class range: `a-9`
}