mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
PR feedback - more tests and some cleanup
This commit is contained in:
@@ -743,6 +743,46 @@ func TestFormatFileOrDirectory_ymlExtFile(t *testing.T) {
|
||||
assert.Equal(t, string(testyaml.FormattedYaml1), string(b))
|
||||
}
|
||||
|
||||
// TestFormatFileOrDirectory_YamlExtFileWithJson verifies that the JSON compatible flow style
|
||||
// YAML content is formatted as such.
|
||||
func TestFormatFileOrDirectory_YamlExtFileWithJson(t *testing.T) {
|
||||
// write the unformatted JSON file contents
|
||||
f, err := ioutil.TempFile("", "yamlfmt*.yaml")
|
||||
assert.NoError(t, err)
|
||||
defer os.Remove(f.Name())
|
||||
err = ioutil.WriteFile(f.Name(), testyaml.UnformattedJSON1, 0600)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// format the file
|
||||
err = FormatFileOrDirectory(f.Name())
|
||||
assert.NoError(t, err)
|
||||
|
||||
// check the result is formatted as yaml
|
||||
b, err := ioutil.ReadFile(f.Name())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, string(testyaml.FormattedFlowYAML1), string(b))
|
||||
}
|
||||
|
||||
// TestFormatFileOrDirectory_JsonExtFileWithNotModified verifies that a file with .json extensions
|
||||
// and JSON contents won't be modified.
|
||||
func TestFormatFileOrDirectory_JsonExtFileWithNotModified(t *testing.T) {
|
||||
// write the unformatted JSON file contents
|
||||
f, err := ioutil.TempFile("", "yamlfmt*.json")
|
||||
assert.NoError(t, err)
|
||||
defer os.Remove(f.Name())
|
||||
err = ioutil.WriteFile(f.Name(), testyaml.UnformattedJSON1, 0600)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// format the file
|
||||
err = FormatFileOrDirectory(f.Name())
|
||||
assert.NoError(t, err)
|
||||
|
||||
// check the result is formatted as yaml
|
||||
b, err := ioutil.ReadFile(f.Name())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, string(testyaml.UnformattedJSON1), string(b))
|
||||
}
|
||||
|
||||
// TestFormatFileOrDirectory_partialKubernetesYamlFile verifies that if a yaml file contains both
|
||||
// Kubernetes and non-Kubernetes documents, it will only format the Kubernetes documents
|
||||
func TestFormatFileOrDirectory_partialKubernetesYamlFile(t *testing.T) {
|
||||
|
||||
@@ -68,6 +68,15 @@ metadata:
|
||||
selfLink: ""
|
||||
`)
|
||||
|
||||
var UnformattedJSON1 = []byte(`
|
||||
{
|
||||
"spec": "a",
|
||||
"status": {"conditions": [3, 1, 2]},
|
||||
"apiVersion": "example.com/v1beta1",
|
||||
"kind": "MyType"
|
||||
}
|
||||
`)
|
||||
|
||||
var FormattedYaml1 = []byte(`apiVersion: example.com/v1beta1
|
||||
kind: MyType
|
||||
spec: a
|
||||
@@ -88,6 +97,11 @@ status2:
|
||||
- 2
|
||||
`)
|
||||
|
||||
var FormattedFlowYAML1 = []byte(
|
||||
`{"apiVersion": "example.com/v1beta1", "kind": "MyType", "spec": "a", "status": {"conditions": [
|
||||
3, 1, 2]}}
|
||||
`)
|
||||
|
||||
var FormattedYaml3 = []byte(`apiVersion: v1
|
||||
kind: List
|
||||
metadata:
|
||||
|
||||
Reference in New Issue
Block a user