mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-29 17:41:13 +00:00
Convert plugins to accept bytes instead of unstruct.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/resid"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
// Resource is map representation of a Kubernetes API resource object
|
||||
@@ -56,6 +57,16 @@ func (r *Resource) DeepCopy() *Resource {
|
||||
return rc
|
||||
}
|
||||
|
||||
// AsYAML returns the resource in Yaml form.
|
||||
// Easier to read than JSON.
|
||||
func (r *Resource) AsYAML() ([]byte, error) {
|
||||
json, err := r.MarshalJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return yaml.JSONToYAML(json)
|
||||
}
|
||||
|
||||
// Behavior returns the behavior for the resource.
|
||||
func (r *Resource) Behavior() types.GenerationBehavior {
|
||||
return r.options.Behavior()
|
||||
|
||||
@@ -54,6 +54,21 @@ var testDeployment = factory.FromMap(
|
||||
|
||||
const deploymentAsString = `{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"pooh"}}`
|
||||
|
||||
func TestAsYAML(t *testing.T) {
|
||||
expected := `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: pooh
|
||||
`
|
||||
yaml, err := testDeployment.AsYAML()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(yaml) != expected {
|
||||
t.Fatalf("--- expected\n%s\n--- got\n%s\n", expected, string(yaml))
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceString(t *testing.T) {
|
||||
tests := []struct {
|
||||
in *Resource
|
||||
|
||||
Reference in New Issue
Block a user