Skip to content

Commit 98fd085

Browse files
WGH-lunny
authored andcommitted
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.
1 parent e9bb75d commit 98fd085

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

modules/validation/binding_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package validation
66

77
import (
8-
"fmt"
98
"net/http"
109
"net/http/httptest"
1110
"testing"
@@ -37,7 +36,12 @@ func performValidationTest(t *testing.T, testCase validationTestCase) {
3736
m := macaron.Classic()
3837

3938
m.Post(testRoute, binding.Validate(testCase.data), func(actual binding.Errors) {
40-
assert.Equal(t, fmt.Sprintf("%+v", testCase.expectedErrors), fmt.Sprintf("%+v", actual))
39+
// see https://github.com/stretchr/testify/issues/435
40+
if actual == nil {
41+
actual = binding.Errors{}
42+
}
43+
44+
assert.Equal(t, testCase.expectedErrors, actual)
4145
})
4246

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

0 commit comments

Comments
 (0)