use a struct to pass multiple pieces of data into templating context

This commit is contained in:
Joel Wetzell
2026-03-04 12:38:51 -06:00
parent 6a21cc2639
commit 572a54d3b2
12 changed files with 82 additions and 46 deletions

View File

@@ -16,7 +16,7 @@ func TestStringCreateFromRegistry(t *testing.T) {
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "string.create",
Params: map[string]any{
"template": "{{.}}",
"template": "{{.Payload}}",
},
})
if err != nil {
@@ -50,31 +50,31 @@ func TestGoodStringCreate(t *testing.T) {
}{
{
name: "string payload",
params: map[string]any{"template": "{{.}}"},
params: map[string]any{"template": "{{.Payload}}"},
payload: "hello",
expected: "hello",
},
{
name: "number payload",
params: map[string]any{"template": "{{.}}"},
params: map[string]any{"template": "{{.Payload}}"},
payload: 4,
expected: "4",
},
{
name: "boolean payload",
params: map[string]any{"template": "{{.}}"},
params: map[string]any{"template": "{{.Payload}}"},
payload: true,
expected: "true",
},
{
name: "struct payload - field",
params: map[string]any{"template": "{{.Data}}"},
params: map[string]any{"template": "{{.Payload.Data}}"},
payload: TestStruct{Data: "test"},
expected: "test",
},
{
name: "struct payload - method",
params: map[string]any{"template": "{{.GetData}}"},
params: map[string]any{"template": "{{.Payload.GetData}}"},
payload: TestStruct{Data: "test"},
expected: "test",
},
@@ -148,7 +148,7 @@ func TestBadStringCreate(t *testing.T) {
params: map[string]any{
"template": "{{.Invalid}}",
},
errorString: "template: template:1:2: executing \"template\" at <.Invalid>: can't evaluate field Invalid in type string",
errorString: "template: template:1:2: executing \"template\" at <.Invalid>: can't evaluate field Invalid in type processor.TemplateData",
},
}