mirror of https://github.com/docker/cli.git
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 <github@gone.nl>
This commit is contained in:
parent
0644aa3906
commit
5aba4860de
|
@ -1,24 +1,24 @@
|
||||||
package manager
|
package manager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
|
is "gotest.tools/v3/assert/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPluginError(t *testing.T) {
|
func TestPluginError(t *testing.T) {
|
||||||
err := NewPluginError("new error")
|
err := NewPluginError("new error")
|
||||||
assert.Error(t, err, "new error")
|
assert.Check(t, is.Error(err, "new error"))
|
||||||
|
|
||||||
inner := fmt.Errorf("testing")
|
inner := fmt.Errorf("testing")
|
||||||
err = wrapAsPluginError(inner, "wrapping")
|
err = wrapAsPluginError(inner, "wrapping")
|
||||||
assert.Error(t, err, "wrapping: testing")
|
assert.Check(t, is.Error(err, "wrapping: testing"))
|
||||||
assert.Assert(t, errors.Is(err, inner))
|
assert.Check(t, is.ErrorIs(err, inner))
|
||||||
|
|
||||||
actual, err := yaml.Marshal(err)
|
actual, err := json.Marshal(err)
|
||||||
assert.NilError(t, err)
|
assert.Check(t, err)
|
||||||
assert.Equal(t, "'wrapping: testing'\n", string(actual))
|
assert.Check(t, is.Equal(`"wrapping: testing"`, string(actual)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue