Consolidate Distributor template parsing
This commit is contained in:
@@ -1725,43 +1725,59 @@ func TestDistributorBatchTemplateRendering(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDistributorBatchTemplateRejectsUnknownAndMalformedVariables(t *testing.T) {
|
||||
func TestDistributorTemplateRejectsUnknownVariables(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
template string
|
||||
render func(string) error
|
||||
}{
|
||||
{name: "Unknown", template: "{report_id}"},
|
||||
{name: "Unclosed", template: "{batch"},
|
||||
{name: "Unopened", template: "batch}"},
|
||||
{name: "Empty", template: "{}"},
|
||||
{
|
||||
name: "SingleReport",
|
||||
template: "{unknown}",
|
||||
render: func(template string) error {
|
||||
_, err := RenderDistributorBundleID(template, DistributorTemplateValues{})
|
||||
return err
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Batch",
|
||||
template: "{report_id}",
|
||||
render: func(template string) error {
|
||||
_, err := RenderDistributorBatchBundleID(template, DistributorBatchTemplateValues{})
|
||||
return err
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := RenderDistributorBatchBundleID(tt.template, DistributorBatchTemplateValues{})
|
||||
err := tt.render(tt.template)
|
||||
if err == nil {
|
||||
t.Fatal("RenderDistributorBatchBundleID() error = nil, want error")
|
||||
t.Fatal("rendering error = nil, want error")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDistributorTemplateRejectsUnknownAndMalformedVariables(t *testing.T) {
|
||||
func TestDistributorTemplateParserRejectsMalformedVariables(t *testing.T) {
|
||||
const name = "notify.distributor.bundle_id_template"
|
||||
tests := []struct {
|
||||
name string
|
||||
template string
|
||||
wantErr string
|
||||
}{
|
||||
{name: "Unknown", template: "{unknown}"},
|
||||
{name: "Unclosed", template: "{location_id"},
|
||||
{name: "Unopened", template: "location_id}"},
|
||||
{name: "Empty", template: "{}"},
|
||||
{name: "Unclosed", template: "{location_id", wantErr: name + " contains an unclosed template variable"},
|
||||
{name: "Unopened", template: "location_id}", wantErr: name + " contains an unopened template variable"},
|
||||
{name: "Empty", template: "{}", wantErr: name + " contains an empty template variable"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := RenderDistributorBundleID(tt.template, DistributorTemplateValues{})
|
||||
if err == nil {
|
||||
t.Fatal("RenderDistributorBundleID() error = nil, want error")
|
||||
_, err := renderDistributorTemplate(name, tt.template, func(variable string) (string, bool) {
|
||||
return "value", variable == "location_id"
|
||||
})
|
||||
if err == nil || err.Error() != tt.wantErr {
|
||||
t.Fatalf("error = %v, want %q", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user