From 5aba4860de4858238b2a50dca053d421911a38e5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 16 Nov 2022 22:08:09 +0100 Subject: [PATCH] cli-plugins/manager: TestPluginError: don't use yaml.Marshal The test used `gopkg.in/yaml.v2` to verify the TextMarshaller implementation, which was implemented to allow printing the errors in JSON formatted output; > This exists primarily to implement encoding.TextMarshaller such that > rendering a plugin as JSON (e.g. for `docker info -f '{{json .CLIPlugins}}'`) > renders the Err field as a useful string and not just `{}`. Given that both yaml.Marshal and json.Marshal use this, we may as well use Go's stdlib. While updating, also changed some of the assertions to checks, so that we don't fail the test early. Signed-off-by: Sebastiaan van Stijn --- cli-plugins/manager/error_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cli-plugins/manager/error_test.go b/cli-plugins/manager/error_test.go index fbdb57fd4d..55222d7042 100644 --- a/cli-plugins/manager/error_test.go +++ b/cli-plugins/manager/error_test.go @@ -1,24 +1,24 @@ package manager import ( + "encoding/json" "fmt" "testing" - "github.com/pkg/errors" - "gopkg.in/yaml.v2" "gotest.tools/v3/assert" + is "gotest.tools/v3/assert/cmp" ) func TestPluginError(t *testing.T) { err := NewPluginError("new error") - assert.Error(t, err, "new error") + assert.Check(t, is.Error(err, "new error")) inner := fmt.Errorf("testing") err = wrapAsPluginError(inner, "wrapping") - assert.Error(t, err, "wrapping: testing") - assert.Assert(t, errors.Is(err, inner)) + assert.Check(t, is.Error(err, "wrapping: testing")) + assert.Check(t, is.ErrorIs(err, inner)) - actual, err := yaml.Marshal(err) - assert.NilError(t, err) - assert.Equal(t, "'wrapping: testing'\n", string(actual)) + actual, err := json.Marshal(err) + assert.Check(t, err) + assert.Check(t, is.Equal(`"wrapping: testing"`, string(actual))) }