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:
Родитель
0644aa3906
Коммит
5aba4860de
|
@ -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)))
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче