upaas/internal/handlers/port_validation_test.go
clawbot 559bfa4131 fix: resolve all golangci-lint issues
Fixes #32

Changes:
- middleware.go: use max() builtin, strconv.Itoa, fix wsl whitespace
- database.go: fix nlreturn, noinlineerr, wsl whitespace
- handlers.go: remove unnecessary template.HTML conversion, unused import
- app.go: extract cleanupContainer to fix nestif, fix lll
- client.go: break long string literals to fix lll
- deploy.go: fix wsl whitespace
- auth_test.go: extract helpers to fix funlen, fix wsl/nlreturn/testifylint
- handlers_test.go: deduplicate IDOR tests, fix paralleltest
- validation_test.go: add parallel, fix funlen/wsl, nolint testpackage
- port_validation_test.go: add parallel, nolint testpackage
- ratelimit_test.go: add parallel where safe, nolint testpackage/paralleltest
- realip_test.go: add parallel, use NewRequestWithContext, fix wsl/funlen
- user.go: (noinlineerr already fixed by database.go pattern)
2026-02-15 21:55:24 -08:00

40 lines
1.1 KiB
Go

package handlers //nolint:testpackage // tests unexported parsePortValues function
import "testing"
func TestParsePortValues(t *testing.T) {
t.Parallel()
tests := []struct {
name string
host string
container string
wantHost int
wantCont int
wantValid bool
}{
{"valid ports", "8080", "80", 8080, 80, true},
{"port 1", "1", "1", 1, 1, true},
{"port 65535", "65535", "65535", 65535, 65535, true},
{"host port above 65535", "99999", "80", 0, 0, false},
{"container port above 65535", "80", "99999", 0, 0, false},
{"both ports above 65535", "70000", "70000", 0, 0, false},
{"zero port", "0", "80", 0, 0, false},
{"negative port", "-1", "80", 0, 0, false},
{"non-numeric", "abc", "80", 0, 0, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
host, cont, valid := parsePortValues(tt.host, tt.container)
if host != tt.wantHost || cont != tt.wantCont || valid != tt.wantValid {
t.Errorf("parsePortValues(%q, %q) = (%d, %d, %v), want (%d, %d, %v)",
tt.host, tt.container, host, cont, valid,
tt.wantHost, tt.wantCont, tt.wantValid)
}
})
}
}