File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package systemd
33import (
44 "strings"
55 "testing"
6+ "text/template"
67)
78
89func TestRenderTemplate (t * testing.T ) {
@@ -106,6 +107,34 @@ func TestRenderTemplate(t *testing.T) {
106107 }
107108 })
108109 }
110+
111+ // Test case for template execution failure
112+ t .Run ("Template execution failure" , func (t * testing.T ) {
113+ // Save the original template
114+ originalTemplate := parsedTemplate
115+
116+ // Replace the template with one that will cause an execution error
117+ parsedTemplate , _ = template .New ("errorTemplate" ).Parse ("{{.NonexistentField}}" )
118+
119+ fields := & Fields {
120+ ServiceID : "testservice" ,
121+ Script : "testscript" ,
122+ TagPrefix : "testprefix" ,
123+ Interval : "testinterval" ,
124+ User : "testuser" ,
125+ Group : "testgroup" ,
126+ }
127+
128+ _ , err := RenderTemplate (fields )
129+ if err == nil {
130+ t .Errorf ("RenderTemplate() expected error, got nil" )
131+ } else if ! strings .Contains (err .Error (), "failed to execute template" ) {
132+ t .Errorf ("RenderTemplate() error = %v, expected 'failed to execute template' error" , err )
133+ }
134+
135+ // Restore the original template
136+ parsedTemplate = originalTemplate
137+ })
109138}
110139
111140func TestValidateFields (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments