Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-11-09 15:49:16 -05:00
pkg-proxy/internal/server/cooldown_patterns_test.go

30 lines
1.2 KiB
Go
Raw Permalink Normal View History

package server
import (
"strings"
"testing"
)
func TestStartRejectsInvalidCooldownPatterns(t *testing.T) {
for _, tc := range []struct {
name string
patterns map[string]string
message string
}{
{"glob", map[string]string{"pkg:npm/[": "0"}, "invalid cooldown package pattern"},
{"class containing scope alias", map[string]string{"pkg:npm/[@a]*": "0"}, "character classes and escapes are not supported"},
{"character class", map[string]string{"pkg:npm/[abcdef]*": "0"}, "character classes and escapes are not supported"},
{"escaped wildcard", map[string]string{`pkg:npm/\*`: "0"}, "character classes and escapes are not supported"},
{"duration", map[string]string{"pkg:npm/*": "invalid"}, "invalid cooldown duration"},
{"aliases", map[string]string{"pkg:npm/@example/*": "0", "pkg:npm/%40example/*": "7d"}, "conflicting cooldown package patterns"},
} {
t.Run(tc.name, func(t *testing.T) {
s := newTestServer(t)
defer s.close()
s.server.cfg.Cooldown.PackagePatterns = tc.patterns
if err := s.server.Start(); err == nil || !strings.Contains(err.Error(), tc.message) {
t.Fatalf("Start error = %v, want %q", err, tc.message)
}
})
}
}