1package webhook23import (4 "errors"5 "testing"67 "github.com/charmbracelet/soft-serve/pkg/ssrf"8)910// TestValidateWebhookURL verifies the wrapper delegates correctly and11// error aliases work across the package boundary. IP range coverage12// is in pkg/ssrf/ssrf_test.go -- here we just confirm the plumbing.13func TestValidateWebhookURL(t *testing.T) {14 tests := []struct {15 name string16 url string17 wantErr bool18 errType error19 }{20 {"valid", "https://1.1.1.1/webhook", false, nil},21 {"bad scheme", "ftp://example.com", true, ErrInvalidScheme},22 {"private IP", "http://127.0.0.1/webhook", true, ErrPrivateIP},23 {"empty", "", true, ErrInvalidURL},24 }2526 for _, tt := range tests {27 t.Run(tt.name, func(t *testing.T) {28 err := ValidateWebhookURL(tt.url)29 if (err != nil) != tt.wantErr {30 t.Errorf("ValidateWebhookURL(%q) error = %v, wantErr %v", tt.url, err, tt.wantErr)31 return32 }33 if tt.wantErr && tt.errType != nil {34 if !errors.Is(err, tt.errType) {35 t.Errorf("ValidateWebhookURL(%q) error = %v, want %v", tt.url, err, tt.errType)36 }37 }38 })39 }40}4142func TestErrorAliases(t *testing.T) {43 if ErrPrivateIP != ssrf.ErrPrivateIP {44 t.Error("ErrPrivateIP should alias ssrf.ErrPrivateIP")45 }46 if ErrInvalidScheme != ssrf.ErrInvalidScheme {47 t.Error("ErrInvalidScheme should alias ssrf.ErrInvalidScheme")48 }49 if ErrInvalidURL != ssrf.ErrInvalidURL {50 t.Error("ErrInvalidURL should alias ssrf.ErrInvalidURL")51 }52}