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

Function TestLoad

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

Source from the content-addressed store, hash-verified

27}
28
29func 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")
35yamlfunc: #@ yamlfunc()
36textfunc: #@ textfunc()
37starfunc: #@ starfunc()
38listdata: #@ data.list()
39loaddata: #@ data.read("funcs/funcs.star")`)
40
41 expectedYAMLTplData := `yamlfunc:
42 yamlfunc: yamlfunc
43textfunc: textfunc
44starfunc:
45- 1
46- 2
47listdata:
48- tpl.yml
49- funcs/funcs.lib.yml
50- funcs/funcs.lib.txt
51- funcs/funcs.star
52loaddata: |2-
53
54 def starfunc():
55 return [1,2]
56 end
57`
58
59 yamlFuncsData := []byte(`
60#@ def/end yamlfunc():
61yamlfunc: yamlfunc`)
62
63 starlarkFuncsData := []byte(`
64def starfunc():
65 return [1,2]
66end`)
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

Callers

nothing calls this directly

Calls 6

RunWithFilesMethod · 0.95
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…