E2e test for run with json

This commit is contained in:
Phani Teja Marupaka
2020-06-08 20:51:01 -07:00
parent b39c522cc1
commit e994b3b566
9 changed files with 76 additions and 122 deletions

View File

@@ -130,17 +130,12 @@ func (r *ByteReader) Read() ([]*yaml.RNode, error) {
if r.AcceptJSON && json.Valid([]byte(inputStr)) {
// convert json to yaml string to generate resource list object
// with appropriate format annotation
yamlValue, err := yaml.ConvertJSONToYAMLString(input.String())
if err != nil {
return nil, err
}
if r.SetAnnotations == nil {
r.SetAnnotations = map[string]string{}
}
if !r.OmitReaderAnnotations {
r.SetAnnotations[kioutil.FormatAnnotation] = JSON
}
inputStr = yamlValue
}
values := strings.Split(inputStr, "\n---\n")

View File

@@ -173,10 +173,11 @@ func TestLocalPackageReader_Read_JSON(t *testing.T) {
}
// TODO: Fix https://github.com/go-yaml/yaml/issues/44 so these are printed correctly
expected := []string{
`{"a": "b", metadata: {annotations: {config.kubernetes.io/index: '0', config.kubernetes.io/path: 'a_test.json'}}}
`{"a": "b", metadata: {annotations: {config.kubernetes.io/format: 'json', config.kubernetes.io/index: '0',
config.kubernetes.io/path: 'a_test.json'}}}
`,
`{"e": "f", "g": {"h": ["i", "j"]}, metadata: {annotations: {config.kubernetes.io/index: '0',
config.kubernetes.io/path: 'b_test.json'}}}
`{"e": "f", "g": {"h": ["i", "j"]}, metadata: {annotations: {config.kubernetes.io/format: 'json',
config.kubernetes.io/index: '0', config.kubernetes.io/path: 'b_test.json'}}}
`,
}
for i := range nodes {