Skip to content

Commit 5767cf0

Browse files
authored
Merge pull request #185 from GoCodeAlone/copilot/add-middlewares-support-http-triggers
Add middlewares support to pipeline HTTP trigger config
2 parents e6233d1 + 82342e8 commit 5767cf0

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

plugins/http/plugin.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ func (p *HTTPPlugin) PipelineTriggerConfigWrappers() map[string]plugin.TriggerCo
161161
if method, ok := cfg["method"]; ok {
162162
route["method"] = method
163163
}
164+
if middlewares, ok := cfg["middlewares"]; ok {
165+
route["middlewares"] = middlewares
166+
}
164167
return map[string]any{
165168
"routes": []any{route},
166169
}

plugins/http/plugin_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,58 @@ func TestStaticFileServerFactory_SPAConfigKey(t *testing.T) {
433433
}
434434
}
435435

436+
func TestPipelineTriggerConfigWrappers(t *testing.T) {
437+
p := New()
438+
wrappers := p.PipelineTriggerConfigWrappers()
439+
wrapper, ok := wrappers["http"]
440+
if !ok {
441+
t.Fatal("missing pipeline trigger config wrapper for http")
442+
}
443+
444+
t.Run("forwards path, method, and middlewares", func(t *testing.T) {
445+
cfg := map[string]any{
446+
"path": "/items",
447+
"method": "GET",
448+
"middlewares": []any{"auth-bearer", "rate-limit"},
449+
}
450+
result := wrapper("list-items", cfg)
451+
routes, ok := result["routes"].([]any)
452+
if !ok || len(routes) != 1 {
453+
t.Fatalf("expected 1 route, got %v", result["routes"])
454+
}
455+
route := routes[0].(map[string]any)
456+
if route["path"] != "/items" {
457+
t.Errorf("path = %v, want /items", route["path"])
458+
}
459+
if route["method"] != "GET" {
460+
t.Errorf("method = %v, want GET", route["method"])
461+
}
462+
mw, ok := route["middlewares"].([]any)
463+
if !ok || len(mw) != 2 {
464+
t.Fatalf("middlewares = %v, want [auth-bearer rate-limit]", route["middlewares"])
465+
}
466+
if mw[0] != "auth-bearer" || mw[1] != "rate-limit" {
467+
t.Errorf("middlewares = %v, want [auth-bearer rate-limit]", mw)
468+
}
469+
if route["workflow"] != "pipeline:list-items" {
470+
t.Errorf("workflow = %v, want pipeline:list-items", route["workflow"])
471+
}
472+
})
473+
474+
t.Run("omits middlewares when not set", func(t *testing.T) {
475+
cfg := map[string]any{
476+
"path": "/items",
477+
"method": "GET",
478+
}
479+
result := wrapper("list-items", cfg)
480+
routes := result["routes"].([]any)
481+
route := routes[0].(map[string]any)
482+
if _, exists := route["middlewares"]; exists {
483+
t.Error("middlewares key should not be present when not configured")
484+
}
485+
})
486+
}
487+
436488
func TestPluginLoaderIntegration(t *testing.T) {
437489
p := New()
438490

0 commit comments

Comments
 (0)