MCPcopy
hub / github.com/carvel-dev/ytt / TestDataListRelativeToDir

Function TestDataListRelativeToDir

pkg/cmd/template/cmd_test.go:91–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

89}
90
91func TestDataListRelativeToDir(t *testing.T) {
92 yamlTplData := []byte(`
93#@ load("@ytt:data", "data")
94#@ load("funcs/funcs.lib.yml", "nested_data_list", "nested_data_read")
95
96rootlist: #@ data.list()
97rootdata: #@ data.read("funcs/data")
98
99nestedlist: #@ nested_data_list()
100nesteddata: #@ nested_data_read()`)
101
102 expectedYAMLTplData := `rootlist:
103- tpl.yml
104- funcs/funcs.lib.yml
105- funcs/data
106rootdata: |-
107 data
108 data
109nestedlist:
110 list:
111 - funcs.lib.yml
112 - data
113nesteddata:
114 data: |-
115 data
116 data
117`
118
119 yamlFuncsData := []byte(`
120#@ load("@ytt:data", "data")
121
122#@ def/end nested_data_list():
123list: #@ data.list()
124
125#@ def/end nested_data_read():
126data: #@ data.read("data")`)
127
128 filesToProcess := files.NewSortedFiles([]*files.File{
129 files.MustNewFileFromSource(files.NewBytesSource("tpl.yml", yamlTplData)),
130 files.MustNewFileFromSource(files.NewBytesSource("funcs/funcs.lib.yml", yamlFuncsData)),
131 files.MustNewFileFromSource(files.NewBytesSource("funcs/data", []byte("data\ndata"))),
132 files.MustNewFileFromSource(files.NewBytesSource("_ytt_lib/lib1/other", []byte("lib1\ndata"))),
133 })
134
135 ui := ui.NewTTY(false)
136 opts := cmdtpl.NewOptions()
137
138 out := opts.RunWithFiles(cmdtpl.Input{Files: filesToProcess}, ui)
139
140 require.NoError(t, out.Err)
141 require.Len(t, out.Files, 1, "unexpected number of output files")
142
143 file := out.Files[0]
144
145 assert.Equal(t, "tpl.yml", file.RelativePath())
146 assert.Equal(t, expectedYAMLTplData, string(file.Bytes()))
147}
148

Callers

nothing calls this directly

Calls 7

RunWithFilesMethod · 0.95
NewSortedFilesFunction · 0.92
MustNewFileFromSourceFunction · 0.92
NewBytesSourceFunction · 0.92
RelativePathMethod · 0.65
BytesMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…