MCPcopy Create free account
hub / github.com/appleboy/CodeGPT / TestProcessTemplate

Function TestProcessTemplate

util/template_test.go:46–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func TestProcessTemplate(t *testing.T) {
47 // Set up test data
48 testTemplateName := "foo.tmpl"
49 testTemplateText := "Hello {{.Name}}!"
50 testData := Data{"Name": "World"}
51
52 // Parse test template
53 tmpl, err := template.New(testTemplateName).Parse(testTemplateText)
54 if err != nil {
55 t.Errorf("Failed to parse test template: %v", err)
56 }
57
58 // Add test template to templates map
59 templates = make(map[string]*template.Template)
60 templates[testTemplateName] = tmpl
61
62 // Process test template
63 buf, err := processTemplate(testTemplateName, testData)
64 if err != nil {
65 t.Errorf("Failed to process template: %v", err)
66 }
67
68 // Check the output
69 expected := "Hello World!"
70 if buf.String() != expected {
71 t.Errorf("Unexpected output. Got: %v, Want: %v", buf.String(), expected)
72 }
73}
74
75func TestLoadTemplatesFromDir(t *testing.T) {
76 // Create a temporary directory for testing

Callers

nothing calls this directly

Calls 2

processTemplateFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected