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>
25 lines
538 B
Go
25 lines
538 B
Go
package manager
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
is "gotest.tools/v3/assert/cmp"
|
|
)
|
|
|
|
func TestPluginError(t *testing.T) {
|
|
err := NewPluginError("new error")
|
|
assert.Check(t, is.Error(err, "new error"))
|
|
|
|
inner := fmt.Errorf("testing")
|
|
err = wrapAsPluginError(inner, "wrapping")
|
|
assert.Check(t, is.Error(err, "wrapping: testing"))
|
|
assert.Check(t, is.ErrorIs(err, inner))
|
|
|
|
actual, err := json.Marshal(err)
|
|
assert.Check(t, err)
|
|
assert.Check(t, is.Equal(`"wrapping: testing"`, string(actual)))
|
|
}
|