mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Fix kyaml tests
This commit is contained in:
@@ -194,7 +194,7 @@ metadata:
|
|||||||
// Test Case
|
// Test Case
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
name: "encode_valid_json",
|
name: "encode_valid_json",
|
||||||
items: []string{
|
items: []string{
|
||||||
`{
|
`{
|
||||||
"a": "a long string that would certainly see a newline introduced by the YAML marshaller abcd123",
|
"a": "a long string that would certainly see a newline introduced by the YAML marshaller abcd123",
|
||||||
@@ -220,7 +220,7 @@ metadata:
|
|||||||
// Test Case
|
// Test Case
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
name: "encode_wrapped_json_as_yaml",
|
name: "encode_wrapped_json_as_yaml",
|
||||||
instance: ByteWriter{
|
instance: ByteWriter{
|
||||||
Sort: true,
|
Sort: true,
|
||||||
WrappingKind: ResourceListKind,
|
WrappingKind: ResourceListKind,
|
||||||
@@ -248,7 +248,7 @@ items:
|
|||||||
// Test Case
|
// Test Case
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
name: "encode_multi_doc_json_as_yaml",
|
name: "encode_multi_doc_json_as_yaml",
|
||||||
items: []string{
|
items: []string{
|
||||||
`{
|
`{
|
||||||
"a": "b",
|
"a": "b",
|
||||||
|
|||||||
@@ -743,26 +743,6 @@ func TestFormatFileOrDirectory_ymlExtFile(t *testing.T) {
|
|||||||
assert.Equal(t, string(testyaml.FormattedYaml1), string(b))
|
assert.Equal(t, string(testyaml.FormattedYaml1), string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestFormatFileOrDirectory_skipYamlExtFileWithJson verifies that the json content is formatted
|
|
||||||
// as yaml
|
|
||||||
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.FormattedJSON1), string(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestFormatFileOrDirectory_partialKubernetesYamlFile verifies that if a yaml file contains both
|
// TestFormatFileOrDirectory_partialKubernetesYamlFile verifies that if a yaml file contains both
|
||||||
// Kubernetes and non-Kubernetes documents, it will only format the Kubernetes documents
|
// Kubernetes and non-Kubernetes documents, it will only format the Kubernetes documents
|
||||||
func TestFormatFileOrDirectory_partialKubernetesYamlFile(t *testing.T) {
|
func TestFormatFileOrDirectory_partialKubernetesYamlFile(t *testing.T) {
|
||||||
|
|||||||
@@ -68,15 +68,6 @@ metadata:
|
|||||||
selfLink: ""
|
selfLink: ""
|
||||||
`)
|
`)
|
||||||
|
|
||||||
var UnformattedJSON1 = []byte(`
|
|
||||||
{
|
|
||||||
"spec": "a",
|
|
||||||
"status": {"conditions": [3, 1, 2]},
|
|
||||||
"apiVersion": "example.com/v1beta1",
|
|
||||||
"kind": "MyType"
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
var FormattedYaml1 = []byte(`apiVersion: example.com/v1beta1
|
var FormattedYaml1 = []byte(`apiVersion: example.com/v1beta1
|
||||||
kind: MyType
|
kind: MyType
|
||||||
spec: a
|
spec: a
|
||||||
@@ -97,20 +88,6 @@ status2:
|
|||||||
- 2
|
- 2
|
||||||
`)
|
`)
|
||||||
|
|
||||||
var FormattedJSON1 = []byte(`{
|
|
||||||
"apiVersion": "example.com/v1beta1",
|
|
||||||
"kind": "MyType",
|
|
||||||
"spec": "a",
|
|
||||||
"status": {
|
|
||||||
"conditions": [
|
|
||||||
3,
|
|
||||||
1,
|
|
||||||
2
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
var FormattedYaml3 = []byte(`apiVersion: v1
|
var FormattedYaml3 = []byte(`apiVersion: v1
|
||||||
kind: List
|
kind: List
|
||||||
metadata:
|
metadata:
|
||||||
|
|||||||
Reference in New Issue
Block a user