Handle parsing of bare sequence yaml nodes

This commit is contained in:
Phani Teja Marupaka
2021-09-17 13:40:56 -07:00
parent 53577a5190
commit e997cc5486
6 changed files with 256 additions and 3 deletions

View File

@@ -39,6 +39,13 @@ a: b #forth
metadata:
`)
var readFileE = []byte(`---
a: b #first
---
- foo # second
- bar
`)
var pkgFile = []byte(``)
func TestLocalPackageReader_Read_empty(t *testing.T) {
@@ -555,3 +562,41 @@ func testOnDiskAndOnMem(t *testing.T, files []mockFile, f func(t *testing.T, pat
f(t, "/", fs)
})
}
func TestLocalPackageReader_ReadBareSeqNodes(t *testing.T) {
testOnDiskAndOnMem(t, []mockFile{
{path: "a/b"},
{path: "a/c"},
{path: "e_test.yaml", content: readFileE},
}, func(t *testing.T, path string, mockFS filesys.FileSystem) {
rfr := LocalPackageReader{
PackagePath: path,
FileSystem: filesys.FileSystemOrOnDisk{FileSystem: mockFS},
WrapBareSeqNode: true,
}
nodes, err := rfr.Read()
require.NoError(t, err)
require.Len(t, nodes, 2)
expected := []string{
`a: b #first
metadata:
annotations:
config.kubernetes.io/index: '0'
config.kubernetes.io/path: 'e_test.yaml'
`,
`bareSeqNodeWrappingKey:
- foo # second
- bar
metadata:
annotations:
config.kubernetes.io/index: '1'
config.kubernetes.io/path: 'e_test.yaml'
`,
}
for i := range nodes {
val, err := nodes[i].String()
require.NoError(t, err)
require.Equal(t, expected[i], val)
}
})
}