From 26bea0d21de96cc7d29f738695649a943c88e1ba Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 5 Apr 2025 13:31:53 +0800 Subject: [PATCH] fix(tests): fix tests for gperr module by stripping ANSI color codes from error messages --- internal/gperr/error_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/gperr/error_test.go b/internal/gperr/error_test.go index 81d0139..1421a0a 100644 --- a/internal/gperr/error_test.go +++ b/internal/gperr/error_test.go @@ -5,6 +5,7 @@ import ( "strings" "testing" + "github.com/yusing/go-proxy/internal/utils/strutils/ansi" . "github.com/yusing/go-proxy/internal/utils/testing" ) @@ -18,11 +19,11 @@ func TestBaseWithSubject(t *testing.T) { withSubjectf := err.Subjectf("%s %s", "foo", "bar") ExpectError(t, err, withSubject) - ExpectEqual(t, withSubject.Error(), "foo: error") + ExpectEqual(t, ansi.StripANSI(withSubject.Error()), "foo: error") ExpectTrue(t, withSubject.Is(err)) ExpectError(t, err, withSubjectf) - ExpectEqual(t, withSubjectf.Error(), "foo bar: error") + ExpectEqual(t, ansi.StripANSI(withSubjectf.Error()), "foo bar: error") ExpectTrue(t, withSubjectf.Is(err)) } @@ -114,9 +115,9 @@ func TestErrorWith(t *testing.T) { func TestErrorStringSimple(t *testing.T) { errFailure := New("generic failure") ne := errFailure.Subject("foo bar") - ExpectEqual(t, ne.Error(), "foo bar: generic failure") + ExpectEqual(t, ansi.StripANSI(ne.Error()), "foo bar: generic failure") ne = ne.Subject("baz") - ExpectEqual(t, ne.Error(), "baz > foo bar: generic failure") + ExpectEqual(t, ansi.StripANSI(ne.Error()), "baz > foo bar: generic failure") } func TestErrorStringNested(t *testing.T) { @@ -153,5 +154,5 @@ func TestErrorStringNested(t *testing.T) { • action 3 > inner3: generic failure • 3 • 3` - ExpectEqual(t, ne.Error(), want) + ExpectEqual(t, ansi.StripANSI(ne.Error()), want) }