From 51f0ff4d9cbca437e3be0acbc9f652b2fa68c392 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Mon, 23 Mar 2020 16:31:45 +0800 Subject: [PATCH] httperrors: fix passing "params" argument --- pkg/httperrors/errors.go | 4 ++-- pkg/httperrors/general_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 pkg/httperrors/general_test.go diff --git a/pkg/httperrors/errors.go b/pkg/httperrors/errors.go index 1602b2c8ab..2ef719bea6 100644 --- a/pkg/httperrors/errors.go +++ b/pkg/httperrors/errors.go @@ -197,9 +197,9 @@ func NewClientError(msg string, params ...interface{}) *httputils.JSONClientErro } func NewUnclassifiedError(msg string, params ...interface{}) *httputils.JSONClientError { - return httputils.NewJsonClientError(httpErrorCode[errors.ErrUnclassified], string(errors.ErrUnclassified), msg, params) + return httputils.NewJsonClientError(httpErrorCode[errors.ErrUnclassified], string(errors.ErrUnclassified), msg, params...) } func NewTooLargeEntityError(msg string, params ...interface{}) *httputils.JSONClientError { - return httputils.NewJsonClientError(httpErrorCode[ErrTooLarge], string(ErrTooLarge), msg, params) + return httputils.NewJsonClientError(httpErrorCode[ErrTooLarge], string(ErrTooLarge), msg, params...) } diff --git a/pkg/httperrors/general_test.go b/pkg/httperrors/general_test.go new file mode 100644 index 0000000000..0b9e061d22 --- /dev/null +++ b/pkg/httperrors/general_test.go @@ -0,0 +1,26 @@ +package httperrors + +import ( + "fmt" + "strings" + "testing" +) + +func TestGeneralError(t *testing.T) { + t.Run("unclassified", func(t *testing.T) { + t.Run("no fmt", func(t *testing.T) { + err := fmt.Errorf("i am an unclassified error") + jce := NewGeneralError(err) + if strings.Contains(jce.Details, "%!(EXTRA") { + t.Errorf("bad error formating: %v", jce) + } + }) + t.Run("fmt", func(t *testing.T) { + err := fmt.Errorf("i am error with plain %%s") + jce := NewGeneralError(err) + if strings.Contains(jce.Details, "%!(EXTRA") { + t.Errorf("bad error formating: %v", jce) + } + }) + }) +}