@@ -38,94 +38,68 @@ var generatedBlockIndentTemplate string
38
38
var fakeGeneratedBlockIndentFile string
39
39
40
40
func TestSingleFileRender (t * testing.T ) {
41
- log := slogext .NewTestLogger (t )
42
- fs , err := testmemfs .WithManifest ("name: testing\n " )
43
- assert .NilError (t , err , "failed to testmemfs.WithManifest" )
44
- m , err := modulestest .NewWithFS (t .Context (), "testing" , fs )
45
- assert .NilError (t , err , "failed to NewWithFS" )
46
-
47
- tpl , err := NewTemplate (m , "virtual-file.tpl" , 0o644 , time .Now (), []byte ("hello world!" ), log , nil )
48
- assert .NilError (t , err , "failed to create basic template" )
49
-
50
- sm := & configuration.Manifest {Name : "testing" }
51
-
52
- st := NewStencil (sm , nil , []* modules.Module {m }, log , false )
53
- err = tpl .Render (st , NewValues (t .Context (), sm , nil ))
54
- assert .NilError (t , err , "expected Render() to not fail" )
41
+ tpl := RenderTemplate (t , nil , nil , "hello world!" )
42
+ assert .Equal (t , len (tpl .Files ), 1 , "expected exactly one file to be rendered" )
55
43
assert .Equal (t , tpl .Files [0 ].String (), "hello world!" , "expected Render() to modify first created file" )
56
44
}
57
45
58
46
func TestMultiFileRender (t * testing.T ) {
59
- log := slogext .NewTestLogger (t )
60
- fs , err := testmemfs .WithManifest ("name: testing\n arguments:\n commands:\n type: list" )
61
- assert .NilError (t , err , "failed to testmemfs.WithManifest" )
62
- m , err := modulestest .NewWithFS (t .Context (), "testing" , fs )
63
- assert .NilError (t , err , "failed to NewWithFS" )
64
-
65
- tpl , err := NewTemplate (m , "multi-file.tpl" , 0o644 ,
66
- time .Now (), []byte (multiFileTemplate ), log , nil )
67
- assert .NilError (t , err , "failed to create template" )
68
-
69
- sm := & configuration.Manifest {Name : "testing" , Arguments : map [string ]any {
70
- "commands" : []string {"hello" , "world" , "command" },
71
- }}
72
-
73
- st := NewStencil (sm , nil , []* modules.Module {m }, log , false )
74
- err = tpl .Render (st , NewValues (t .Context (), sm , nil ))
75
- assert .NilError (t , err , "expected Render() to not fail" )
47
+ tpl := RenderTemplate (t ,
48
+ & configuration.Manifest {
49
+ Arguments : map [string ]any {
50
+ "commands" : []string {"hello" , "world" , "command" },
51
+ },
52
+ },
53
+ & configuration.TemplateRepositoryManifest {
54
+ Arguments : map [string ]configuration.Argument {
55
+ "commands" : {},
56
+ },
57
+ }, multiFileTemplate ,
58
+ )
76
59
assert .Equal (t , len (tpl .Files ), 3 , "expected Render() to create 3 files" )
77
60
78
61
for i , f := range tpl .Files {
79
- assert .Equal (t , f .String (), "command" , "rendered template %d contents differred " , i )
62
+ assert .Equal (t , f .String (), "command" , "rendered template %d contents differed " , i )
80
63
}
81
64
}
82
65
83
66
func TestMultiFileWithInputRender (t * testing.T ) {
84
- log := slogext .NewTestLogger (t )
85
- fs , err := testmemfs .WithManifest ("name: testing\n arguments:\n commands:\n type: list" )
86
- assert .NilError (t , err , "failed to testmemfs.WithManifest" )
87
- m , err := modulestest .NewWithFS (t .Context (), "testing" , fs )
88
- assert .NilError (t , err , "failed to NewWithFS" )
89
-
90
- tpl , err := NewTemplate (m , "multi-file-input.tpl" , 0o644 ,
91
- time .Now (), []byte (multiFileInputTemplate ), log , nil )
92
- assert .NilError (t , err , "failed to create template" )
93
-
94
- sm := & configuration.Manifest {Name : "testing" , Arguments : map [string ]any {
95
- "commands" : []string {"hello" , "world" , "command" },
96
- }}
67
+ mf := & configuration.Manifest {
68
+ Arguments : map [string ]any {
69
+ "commands" : []string {"hello" , "world" , "command" },
70
+ },
71
+ }
97
72
98
- st := NewStencil (sm , nil , []* modules.Module {m }, log , false )
99
- err = tpl .Render (st , NewValues (t .Context (), sm , nil ))
100
- assert .NilError (t , err , "expected Render() to not fail" )
73
+ tpl := RenderTemplate (t ,
74
+ mf ,
75
+ & configuration.TemplateRepositoryManifest {
76
+ Arguments : map [string ]configuration.Argument {
77
+ "commands" : {},
78
+ },
79
+ }, multiFileInputTemplate ,
80
+ )
101
81
assert .Equal (t , len (tpl .Files ), 3 , "expected Render() to create 3 files" )
102
82
103
83
for i , f := range tpl .Files {
104
- assert .Equal (t , ( sm .Arguments ["commands" ].([]string )) [i ], f . String (), "rendered template %d contents differred " , i )
84
+ assert .Equal (t , f . String (), mf .Arguments ["commands" ].([]string )[i ], "rendered template %d contents differed " , i )
105
85
}
106
86
}
107
87
108
88
func TestIncludeArgumentPassthrough (t * testing.T ) {
109
- log := slogext .NewTestLogger (t )
110
- fs , err := testmemfs .WithManifest ("name: testing\n arguments:\n commands:\n type: list" )
111
- assert .NilError (t , err , "failed to testmemfs.WithManifest" )
112
- m , err := modulestest .NewWithFS (t .Context (), "testing" , fs )
113
- assert .NilError (t , err , "failed to NewWithFS" )
114
-
115
- tpl , err := NewTemplate (m , "apply-template-passthrough.tpl" , 0o644 ,
116
- time .Now (), []byte (includePassthroughTemplate ), log , nil )
117
- assert .NilError (t , err , "failed to create template" )
118
-
119
- sm := & configuration.Manifest {Name : "testing" , Arguments : map [string ]any {
120
- "commands" : []string {"hello" , "world" , "command" },
121
- }}
122
-
123
- st := NewStencil (sm , nil , []* modules.Module {m }, log , false )
124
- err = tpl .Render (st , NewValues (t .Context (), sm , nil ))
125
- assert .NilError (t , err , "expected Render() to not fail" )
89
+ tpl := RenderTemplate (t ,
90
+ & configuration.Manifest {
91
+ Arguments : map [string ]any {
92
+ "commands" : []string {"hello" , "world" , "command" },
93
+ },
94
+ },
95
+ & configuration.TemplateRepositoryManifest {
96
+ Arguments : map [string ]configuration.Argument {
97
+ "commands" : {},
98
+ },
99
+ }, includePassthroughTemplate ,
100
+ )
126
101
assert .Equal (t , len (tpl .Files ), 1 , "expected Render() to create 1 files" )
127
-
128
- assert .Equal (t , "testing" , tpl .Files [0 ].String (), "rendered template contents differed" )
102
+ assert .Equal (t , t .Name (), tpl .Files [0 ].String (), "rendered template contents differed" )
129
103
}
130
104
131
105
func TestGeneratedBlock (t * testing.T ) {
0 commit comments