mirror of
https://github.com/traefik/traefik.git
synced 2026-06-14 19:20:20 -04:00
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.
This commit is contained in:
parent
367d68f2b4
commit
bf09531b8d
1 changed files with 69 additions and 0 deletions
69
pkg/server/middleware/observability_test.go
Normal file
69
pkg/server/middleware/observability_test.go
Normal file
|
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue