mirror of
https://github.com/MedUnes/go-kata.git
synced 2026-07-28 10:40:14 +07:00
add test
This commit is contained in:
@@ -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: "<nil MyError>",
|
||||
},
|
||||
{
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user