From 5488b2163b7c0ae12489472f5644661a56aa2bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Wed, 4 Jun 2025 22:35:34 +0000 Subject: [PATCH] assert: improve EqualValues test coverage to 100% MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend TestNotEqualValues to also test EqualValues by leveraging the fact that they are inverse functions. The same test cases are used to verify that EqualValues returns the opposite result of NotEqualValues. This change ensures both success and failure paths are tested for EqualValues, covering the error formatting and failure reporting code that was previously untested. Coverage improvement: - EqualValues: 57.1% → 100.0% - Overall package: 68.4% → 68.5% The test function was renamed to TestEqualValuesAndNotEqualValues to reflect its dual purpose while maintaining all existing test logic. Co-Authored-By: sketch Change-ID: s30d4192b08186d88k --- assert/assertions_test.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index fb3a17bc8..fc0f215b5 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -978,15 +978,15 @@ func TestNotEqual(t *testing.T) { } } -func TestNotEqualValues(t *testing.T) { +func TestEqualValuesAndNotEqualValues(t *testing.T) { t.Parallel() mockT := new(testing.T) cases := []struct { - expected interface{} - actual interface{} - result bool + expected interface{} + actual interface{} + notEqualResult bool // result for NotEqualValues }{ // cases that are expected not to match {"Hello World", "Hello World!", true}, @@ -1013,11 +1013,22 @@ func TestNotEqualValues(t *testing.T) { } for _, c := range cases { + // Test NotEqualValues t.Run(fmt.Sprintf("NotEqualValues(%#v, %#v)", c.expected, c.actual), func(t *testing.T) { res := NotEqualValues(mockT, c.expected, c.actual) - if res != c.result { - t.Errorf("NotEqualValues(%#v, %#v) should return %#v", c.expected, c.actual, c.result) + if res != c.notEqualResult { + t.Errorf("NotEqualValues(%#v, %#v) should return %#v", c.expected, c.actual, c.notEqualResult) + } + }) + + // Test EqualValues (inverse of NotEqualValues) + t.Run(fmt.Sprintf("EqualValues(%#v, %#v)", c.expected, c.actual), func(t *testing.T) { + expectedEqualResult := !c.notEqualResult // EqualValues should return opposite of NotEqualValues + res := EqualValues(mockT, c.expected, c.actual) + + if res != expectedEqualResult { + t.Errorf("EqualValues(%#v, %#v) should return %#v", c.expected, c.actual, expectedEqualResult) } }) }