(t *testing.T)
| 89 | } |
| 90 | |
| 91 | func 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 | |
| 96 | rootlist: #@ data.list() |
| 97 | rootdata: #@ data.read("funcs/data") |
| 98 | |
| 99 | nestedlist: #@ nested_data_list() |
| 100 | nesteddata: #@ nested_data_read()`) |
| 101 | |
| 102 | expectedYAMLTplData := `rootlist: |
| 103 | - tpl.yml |
| 104 | - funcs/funcs.lib.yml |
| 105 | - funcs/data |
| 106 | rootdata: |- |
| 107 | data |
| 108 | data |
| 109 | nestedlist: |
| 110 | list: |
| 111 | - funcs.lib.yml |
| 112 | - data |
| 113 | nesteddata: |
| 114 | data: |- |
| 115 | data |
| 116 | data |
| 117 | ` |
| 118 | |
| 119 | yamlFuncsData := []byte(` |
| 120 | #@ load("@ytt:data", "data") |
| 121 | |
| 122 | #@ def/end nested_data_list(): |
| 123 | list: #@ data.list() |
| 124 | |
| 125 | #@ def/end nested_data_read(): |
| 126 | data: #@ 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…