test: Add edge case for canCapturePublicURL nil inputs
Tests the early return paths when config or request are nil.
This commit is contained in:
parent
f0688db9af
commit
b9f9077496
1 changed files with 44 additions and 0 deletions
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rcourtman/pulse-go-rewrite/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsDirectLoopbackRequest(t *testing.T) {
|
func TestIsDirectLoopbackRequest(t *testing.T) {
|
||||||
|
|
@ -736,3 +738,45 @@ func TestShouldAppendForwardedPort(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCanCapturePublicURL_NilInputs(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||||
|
cfg := &config.Config{}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
cfg *config.Config
|
||||||
|
req *http.Request
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "nil config",
|
||||||
|
cfg: nil,
|
||||||
|
req: req,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "nil request",
|
||||||
|
cfg: cfg,
|
||||||
|
req: nil,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "both nil",
|
||||||
|
cfg: nil,
|
||||||
|
req: nil,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got := canCapturePublicURL(tt.cfg, tt.req)
|
||||||
|
if got != tt.want {
|
||||||
|
t.Errorf("canCapturePublicURL() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue