test: improve coverage across package

This commit is contained in:
2026-05-01 14:09:10 +05:30
parent e1c68ec7d0
commit e3f1f5046a
18 changed files with 2652 additions and 6 deletions

45
errors_test.go Normal file
View File

@@ -0,0 +1,45 @@
package mellaris
import (
"errors"
"testing"
)
func TestConfigError_Error(t *testing.T) {
e := ConfigError{Field: "port", Err: errors.New("must be > 0")}
want := "invalid config: port: must be > 0"
if got := e.Error(); got != want {
t.Errorf("Error() = %q, want %q", got, want)
}
}
func TestConfigError_Error_NilErr(t *testing.T) {
e := ConfigError{Field: "host", Err: nil}
want := "invalid config: host: %!s(<nil>)"
if got := e.Error(); got != want {
t.Errorf("Error() = %q, want %q", got, want)
}
}
func TestConfigError_Unwrap(t *testing.T) {
wrapped := errors.New("inner error")
e := ConfigError{Field: "field", Err: wrapped}
if got := e.Unwrap(); got != wrapped {
t.Errorf("Unwrap() = %v, want %v", got, wrapped)
}
}
func TestConfigError_Unwrap_Nil(t *testing.T) {
e := ConfigError{Field: "field"}
if got := e.Unwrap(); got != nil {
t.Errorf("Unwrap() = %v, want nil", got)
}
}
func TestConfigError_ErrorsIs(t *testing.T) {
wrapped := errors.New("inner")
e := ConfigError{Field: "x", Err: wrapped}
if !errors.Is(e, wrapped) {
t.Error("errors.Is should find wrapped error")
}
}