From 91c062b174f20e335327b3ef57f60aa385c3a86c Mon Sep 17 00:00:00 2001 From: maksim bondarenko Date: Mon, 23 Mar 2026 16:40:30 +0200 Subject: [PATCH] add test --- .../20-nil-interface-gotcha/myerror_test.go | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/04-errors-semantics/20-nil-interface-gotcha/myerror_test.go b/04-errors-semantics/20-nil-interface-gotcha/myerror_test.go index 4f78a21..fa2d4ce 100644 --- a/04-errors-semantics/20-nil-interface-gotcha/myerror_test.go +++ b/04-errors-semantics/20-nil-interface-gotcha/myerror_test.go @@ -97,3 +97,31 @@ func TestErrorsAsExtractionMatrix(t *testing.T) { }) } } + +func TestErrorMethodOutput(t *testing.T) { + tests := []struct { + name string + err *MyError + expectedMsg string + }{ + { + name: "nil receiver", + err: nil, + expectedMsg: "", + }, + { + name: "normal error", + err: &MyError{Op: "test-operation"}, + expectedMsg: "operation failed: test-operation", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + msg := tt.err.Error() + if msg != tt.expectedMsg { + t.Errorf("expected message: %q, got: %q", tt.expectedMsg, msg) + } + }) + } +}