Files
at-container-registry/pkg/appview/handlers/common_test.go
T
2025-10-28 17:40:11 -05:00

77 lines
1.4 KiB
Go

package handlers
import "testing"
func TestTrimRegistryURL(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "https prefix",
input: "https://atcr.io",
expected: "atcr.io",
},
{
name: "http prefix",
input: "http://atcr.io",
expected: "atcr.io",
},
{
name: "no prefix",
input: "atcr.io",
expected: "atcr.io",
},
{
name: "with port https",
input: "https://localhost:5000",
expected: "localhost:5000",
},
{
name: "with port http",
input: "http://registry.example.com:443",
expected: "registry.example.com:443",
},
{
name: "empty string",
input: "",
expected: "",
},
{
name: "with path",
input: "https://atcr.io/v2/",
expected: "atcr.io/v2/",
},
{
name: "IP address https",
input: "https://127.0.0.1:5000",
expected: "127.0.0.1:5000",
},
{
name: "IP address http",
input: "http://192.168.1.1",
expected: "192.168.1.1",
},
{
name: "only http://",
input: "http://",
expected: "",
},
{
name: "only https://",
input: "https://",
expected: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := TrimRegistryURL(tt.input)
if result != tt.expected {
t.Errorf("TrimRegistryURL(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}