Explorar el Código

Fix lax comparison in validation tests (#7815)

If you add t.Logf("%+v %+v", actual, testCase.expectedErrors) to
the test code, you'll notice that only Errors' Messages are being
compared:

    --- PASS: Test_ValidURLValidation/Invalid_schema (0.00s)
    binding_test.go:43: [Url] [Url]

FieldNames and Classification are ignored in comparison.

Moreover, an Errors slice with a single Error with empty message
is formatted as '[]' (the same as empty slice), which is also
error-prone. I discovered this when working on #7791 when one test which
was not supposed to pass did pass. https://play.golang.org/p/qC4wVLrm4NG

This commit changes the test to do the comparison properly.
tags/v1.10.0-rc1
WGH hace 4 años
padre
commit
98fd085039
Se han modificado 1 ficheros con 6 adiciones y 2 borrados
  1. 6
    2
      modules/validation/binding_test.go

+ 6
- 2
modules/validation/binding_test.go Ver fichero

package validation package validation


import ( import (
"fmt"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
m := macaron.Classic() m := macaron.Classic()


m.Post(testRoute, binding.Validate(testCase.data), func(actual binding.Errors) { m.Post(testRoute, binding.Validate(testCase.data), func(actual binding.Errors) {
assert.Equal(t, fmt.Sprintf("%+v", testCase.expectedErrors), fmt.Sprintf("%+v", actual))
// see https://github.com/stretchr/testify/issues/435
if actual == nil {
actual = binding.Errors{}
}

assert.Equal(t, testCase.expectedErrors, actual)
}) })


req, err := http.NewRequest("POST", testRoute, nil) req, err := http.NewRequest("POST", testRoute, nil)

Cargando…
Cancelar
Guardar