Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tests #2275

Merged
merged 14 commits into from Oct 6, 2022
36 changes: 18 additions & 18 deletions bind_test.go
Expand Up @@ -190,13 +190,13 @@ func TestToMultipleFields(t *testing.T) {
}

func TestBindJSON(t *testing.T) {
assert := assert.New(t)
testBindOkay(assert, strings.NewReader(userJSON), nil, MIMEApplicationJSON)
testBindOkay(assert, strings.NewReader(userJSON), dummyQuery, MIMEApplicationJSON)
testBindArrayOkay(assert, strings.NewReader(usersJSON), nil, MIMEApplicationJSON)
testBindArrayOkay(assert, strings.NewReader(usersJSON), dummyQuery, MIMEApplicationJSON)
testBindError(assert, strings.NewReader(invalidContent), MIMEApplicationJSON, &json.SyntaxError{})
testBindError(assert, strings.NewReader(userJSONInvalidType), MIMEApplicationJSON, &json.UnmarshalTypeError{})
assertion := assert.New(t)
testBindOkay(assertion, strings.NewReader(userJSON), nil, MIMEApplicationJSON)
testBindOkay(assertion, strings.NewReader(userJSON), dummyQuery, MIMEApplicationJSON)
testBindArrayOkay(assertion, strings.NewReader(usersJSON), nil, MIMEApplicationJSON)
testBindArrayOkay(assertion, strings.NewReader(usersJSON), dummyQuery, MIMEApplicationJSON)
testBindError(assertion, strings.NewReader(invalidContent), MIMEApplicationJSON, &json.SyntaxError{})
testBindError(assertion, strings.NewReader(userJSONInvalidType), MIMEApplicationJSON, &json.UnmarshalTypeError{})
}

func TestBindXML(t *testing.T) {
Expand All @@ -217,17 +217,17 @@ func TestBindXML(t *testing.T) {
}

func TestBindForm(t *testing.T) {
assert := assert.New(t)
assertion := assert.New(t)
aldas marked this conversation as resolved.
Show resolved Hide resolved

testBindOkay(assert, strings.NewReader(userForm), nil, MIMEApplicationForm)
testBindOkay(assert, strings.NewReader(userForm), dummyQuery, MIMEApplicationForm)
testBindOkay(assertion, strings.NewReader(userForm), nil, MIMEApplicationForm)
testBindOkay(assertion, strings.NewReader(userForm), dummyQuery, MIMEApplicationForm)
e := New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userForm))
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
req.Header.Set(HeaderContentType, MIMEApplicationForm)
err := c.Bind(&[]struct{ Field string }{})
assert.Error(err)
assertion.Error(err)
}

func TestBindQueryParams(t *testing.T) {
Expand Down Expand Up @@ -317,14 +317,14 @@ func TestBindUnmarshalParam(t *testing.T) {
err := c.Bind(&result)
ts := Timestamp(time.Date(2016, 12, 6, 19, 9, 5, 0, time.UTC))

assert := assert.New(t)
if assert.NoError(err) {
assertion := assert.New(t)
aldas marked this conversation as resolved.
Show resolved Hide resolved
if assertion.NoError(err) {
// assert.Equal( Timestamp(reflect.TypeOf(&Timestamp{}), time.Date(2016, 12, 6, 19, 9, 5, 0, time.UTC)), result.T)
assert.Equal(ts, result.T)
assert.Equal(StringArray([]string{"one", "two", "three"}), result.SA)
assert.Equal([]Timestamp{ts, ts}, result.TA)
assert.Equal(Struct{""}, result.ST) // child struct does not have a field with matching tag
assert.Equal("baz", result.StWithTag.Foo) // child struct has field with matching tag
assertion.Equal(ts, result.T)
assertion.Equal(StringArray([]string{"one", "two", "three"}), result.SA)
assertion.Equal([]Timestamp{ts, ts}, result.TA)
assertion.Equal(Struct{""}, result.ST) // child struct does not have a field with matching tag
assertion.Equal("baz", result.StWithTag.Foo) // child struct has field with matching tag
}
}

Expand Down
7 changes: 5 additions & 2 deletions context.go
Expand Up @@ -181,7 +181,7 @@ type (
// Logger returns the `Logger` instance.
Logger() Logger

// Set the logger
// SetLogger Set the logger
SetLogger(l Logger)

// Echo returns the `Echo` instance.
Expand Down Expand Up @@ -389,7 +389,10 @@ func (c *context) FormFile(name string) (*multipart.FileHeader, error) {
if err != nil {
return nil, err
}
f.Close()
err = f.Close()
aldas marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
return fh, nil
}

Expand Down