Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package merrors
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestInvalidArgumentSupportsBrokenArgumentName(t *testing.T) {
|
|
t.Run("without argument name keeps old behavior", func(t *testing.T) {
|
|
err := InvalidArgument("value is missing")
|
|
expected := "invalidArgError: value is missing"
|
|
if err.Error() != expected {
|
|
t.Fatalf("unexpected error message: %s", err)
|
|
}
|
|
if !errors.Is(err, ErrInvalidArg) {
|
|
t.Fatalf("error should wrap ErrInvalidArg")
|
|
}
|
|
})
|
|
|
|
t.Run("single argument name", func(t *testing.T) {
|
|
err := InvalidArgument("value is missing", "bot_token_env")
|
|
expected := `invalidArgError: broken argument "bot_token_env": value is missing`
|
|
if err.Error() != expected {
|
|
t.Fatalf("unexpected error message: %s", err)
|
|
}
|
|
})
|
|
|
|
t.Run("multiple argument names", func(t *testing.T) {
|
|
err := InvalidArgument("value mismatch", "bot_token_env", "chat_id_env", " ")
|
|
expected := `invalidArgError: broken arguments "bot_token_env", "chat_id_env": value mismatch`
|
|
if err.Error() != expected {
|
|
t.Fatalf("unexpected error message: %s", err)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestInvalidArgumentWrapSupportsBrokenArgumentName(t *testing.T) {
|
|
base := errors.New("root cause")
|
|
err := InvalidArgumentWrap(base, "value is missing", "bot_token_env")
|
|
if !strings.Contains(err.Error(), `invalidArgError: broken argument "bot_token_env": value is missing`) {
|
|
t.Fatalf("wrapped error should include broken argument name: %s", err)
|
|
}
|
|
if !errors.Is(err, ErrInvalidArg) || !errors.Is(err, base) {
|
|
t.Fatalf("wrapped error should preserve all error layers")
|
|
}
|
|
}
|