From bf09531b8d632fbd5ca1e99eaa37c846204d8936 Mon Sep 17 00:00:00 2001 From: deepak Date: Thu, 7 May 2026 18:33:42 +0530 Subject: [PATCH] test: add unit tests for IsPingEntryPoint Covers nil receiver, nil ping config, matching entry point, non-matching entry point, and unrelated entry point on the same instance. --- pkg/server/middleware/observability_test.go | 69 +++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 pkg/server/middleware/observability_test.go diff --git a/pkg/server/middleware/observability_test.go b/pkg/server/middleware/observability_test.go new file mode 100644 index 0000000000..d75a8f2d05 --- /dev/null +++ b/pkg/server/middleware/observability_test.go @@ -0,0 +1,69 @@ +package middleware + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/traefik/traefik/v3/pkg/config/static" + "github.com/traefik/traefik/v3/pkg/ping" +) + +func TestIsPingEntryPoint(t *testing.T) { + testCases := []struct { + desc string + mgr *ObservabilityMgr + entryPointName string + expected bool + }{ + { + desc: "nil ObservabilityMgr receiver", + mgr: nil, + entryPointName: "websecure", + expected: false, + }, + { + desc: "ping config is nil", + mgr: &ObservabilityMgr{config: static.Configuration{}}, + entryPointName: "websecure", + expected: false, + }, + { + desc: "entry point matches configured ping entry point", + mgr: &ObservabilityMgr{ + config: static.Configuration{ + Ping: &ping.Handler{EntryPoint: "websecure"}, + }, + }, + entryPointName: "websecure", + expected: true, + }, + { + desc: "entry point does not match configured ping entry point", + mgr: &ObservabilityMgr{ + config: static.Configuration{ + Ping: &ping.Handler{EntryPoint: "websecure"}, + }, + }, + entryPointName: "web", + expected: false, + }, + { + desc: "non-ping entry point on same traefik instance", + mgr: &ObservabilityMgr{ + config: static.Configuration{ + Ping: &ping.Handler{EntryPoint: "ping"}, + }, + }, + entryPointName: "websecure", + expected: false, + }, + } + + for _, test := range testCases { + t.Run(test.desc, func(t *testing.T) { + t.Parallel() + + assert.Equal(t, test.expected, test.mgr.IsPingEntryPoint(test.entryPointName)) + }) + } +}