(t *testing.T)
| 27 | } |
| 28 | |
| 29 | func TestLoad(t *testing.T) { |
| 30 | yamlTplData := []byte(` |
| 31 | #@ load("@ytt:data", "data") |
| 32 | #@ load("funcs/funcs.lib.yml", "yamlfunc") |
| 33 | #@ load("funcs/funcs.lib.txt", "textfunc") |
| 34 | #@ load("funcs/funcs.star", "starfunc") |
| 35 | yamlfunc: #@ yamlfunc() |
| 36 | textfunc: #@ textfunc() |
| 37 | starfunc: #@ starfunc() |
| 38 | listdata: #@ data.list() |
| 39 | loaddata: #@ data.read("funcs/funcs.star")`) |
| 40 | |
| 41 | expectedYAMLTplData := `yamlfunc: |
| 42 | yamlfunc: yamlfunc |
| 43 | textfunc: textfunc |
| 44 | starfunc: |
| 45 | - 1 |
| 46 | - 2 |
| 47 | listdata: |
| 48 | - tpl.yml |
| 49 | - funcs/funcs.lib.yml |
| 50 | - funcs/funcs.lib.txt |
| 51 | - funcs/funcs.star |
| 52 | loaddata: |2- |
| 53 | |
| 54 | def starfunc(): |
| 55 | return [1,2] |
| 56 | end |
| 57 | ` |
| 58 | |
| 59 | yamlFuncsData := []byte(` |
| 60 | #@ def/end yamlfunc(): |
| 61 | yamlfunc: yamlfunc`) |
| 62 | |
| 63 | starlarkFuncsData := []byte(` |
| 64 | def starfunc(): |
| 65 | return [1,2] |
| 66 | end`) |
| 67 | |
| 68 | txtFuncsData := []byte(`(@ def textfunc(): @)textfunc(@ end @)`) |
| 69 | |
| 70 | filesToProcess := []*files.File{ |
| 71 | files.MustNewFileFromSource(files.NewBytesSource("tpl.yml", yamlTplData)), |
| 72 | files.MustNewFileFromSource(files.NewBytesSource("funcs/funcs.lib.yml", yamlFuncsData)), |
| 73 | files.MustNewFileFromSource(files.NewBytesSource("funcs/funcs.lib.txt", txtFuncsData)), |
| 74 | files.MustNewFileFromSource(files.NewBytesSource("funcs/funcs.star", starlarkFuncsData)), |
| 75 | } |
| 76 | |
| 77 | ui := ui.NewTTY(false) |
| 78 | opts := cmdtpl.NewOptions() |
| 79 | |
| 80 | out := opts.RunWithFiles(cmdtpl.Input{Files: filesToProcess}, ui) |
| 81 | |
| 82 | require.NoError(t, out.Err) |
| 83 | require.Len(t, out.Files, 1, "unexpected number of output files") |
| 84 | |
| 85 | file := out.Files[0] |
| 86 |
nothing calls this directly
no test coverage detected
searching dependent graphs…