mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Handle errors
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -1671,7 +1672,8 @@ func TestSetName(t *testing.T) {
|
||||
if err := rn.UnmarshalJSON([]byte(deploymentBiggerJson)); err != nil {
|
||||
t.Fatalf("unexpected unmarshaljson err: %v", err)
|
||||
}
|
||||
rn.SetName("marge")
|
||||
err := rn.SetName("marge")
|
||||
require.NoError(t, err)
|
||||
if expected, actual := "marge", rn.GetName(); expected != actual {
|
||||
t.Fatalf("expected '%s', got '%s'", expected, actual)
|
||||
}
|
||||
@@ -1682,12 +1684,15 @@ func TestSetNamespace(t *testing.T) {
|
||||
if err := rn.UnmarshalJSON([]byte(deploymentBiggerJson)); err != nil {
|
||||
t.Fatalf("unexpected unmarshaljson err: %v", err)
|
||||
}
|
||||
rn.SetNamespace("flanders")
|
||||
meta, _ := rn.GetMeta()
|
||||
err := rn.SetNamespace("flanders")
|
||||
require.NoError(t, err)
|
||||
meta, err := rn.GetMeta()
|
||||
require.NoError(t, err)
|
||||
if expected, actual := "flanders", meta.Namespace; expected != actual {
|
||||
t.Fatalf("expected '%s', got '%s'", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetLabels(t *testing.T) {
|
||||
rn := NewRNode(nil)
|
||||
if err := rn.UnmarshalJSON([]byte(deploymentBiggerJson)); err != nil {
|
||||
|
||||
@@ -213,7 +213,10 @@ func String(node *yaml.Node, opts ...string) (string, error) {
|
||||
b := &bytes.Buffer{}
|
||||
e := NewEncoder(b)
|
||||
err := e.Encode(node)
|
||||
e.Close()
|
||||
errClose := e.Close()
|
||||
if err == nil {
|
||||
err = errClose
|
||||
}
|
||||
val := b.String()
|
||||
if optsSet.Has(Trim) {
|
||||
val = strings.TrimSpace(val)
|
||||
|
||||
Reference in New Issue
Block a user