diff --git a/errors.go b/errors.go index 9c10933..755ae32 100644 --- a/errors.go +++ b/errors.go @@ -8,7 +8,7 @@ type ErrTemplateNotFound struct { } func (e ErrTemplateNotFound) Error() string { - return fmt.Sprintf("template %s not found", e.Name) + return fmt.Sprintf("template '%s' not found", e.Name) } // ErrTemplateExecution is returned when a template fails to execute. @@ -18,7 +18,7 @@ type ErrTemplateExecution struct { } func (e ErrTemplateExecution) Error() string { - return fmt.Sprintf("failed to execute template %s: %v", e.Name, e.Err) + return fmt.Sprintf("failed to execute template '%s': '%v'", e.Name, e.Err) } func (e ErrTemplateExecution) Unwrap() error { diff --git a/errors_test.go b/errors_test.go new file mode 100644 index 0000000..036276c --- /dev/null +++ b/errors_test.go @@ -0,0 +1,29 @@ +package templator + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestErrTemplateNotFound_Error(t *testing.T) { + t.Parallel() + + e := ErrTemplateNotFound{Name: "foo"} + + got := e.Error() + assert.Equal(t, "template 'foo' not found", got) +} + +func TestErrTemplateExecution_Error(t *testing.T) { + t.Parallel() + + e := ErrTemplateExecution{ + Name: "foo", + Err: errors.New("bar"), + } + + got := e.Error() + assert.Equal(t, "failed to execute template 'foo': 'bar'", got) +} diff --git a/template_validator_test.go b/template_validator_test.go index 4473ada..979220f 100644 --- a/template_validator_test.go +++ b/template_validator_test.go @@ -92,6 +92,8 @@ func Test_validateField(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + t.Parallel() + err := validateField(tc.typ, tc.fieldPath) if tc.wantErr {