66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package appview
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"atcr.io/pkg/atproto"
|
|
)
|
|
|
|
func TestResolveHoldURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "DID with HTTPS domain",
|
|
input: "did:web:hold.example.com",
|
|
expected: "https://hold.example.com",
|
|
},
|
|
{
|
|
name: "DID with HTTP and port (IP)",
|
|
input: "did:web:172.28.0.3:8080",
|
|
expected: "http://172.28.0.3:8080",
|
|
},
|
|
{
|
|
name: "DID with HTTP and port (localhost)",
|
|
input: "did:web:127.0.0.1:8080",
|
|
expected: "http://127.0.0.1:8080",
|
|
},
|
|
{
|
|
name: "DID with localhost",
|
|
input: "did:web:localhost:8080",
|
|
expected: "http://localhost:8080",
|
|
},
|
|
{
|
|
name: "Already HTTPS URL (passthrough)",
|
|
input: "https://hold.example.com",
|
|
expected: "https://hold.example.com",
|
|
},
|
|
{
|
|
name: "Already HTTP URL (passthrough)",
|
|
input: "http://172.28.0.3:8080",
|
|
expected: "http://172.28.0.3:8080",
|
|
},
|
|
{
|
|
name: "Plain hostname (fallback to HTTPS)",
|
|
input: "hold.example.com",
|
|
expected: "https://hold.example.com",
|
|
},
|
|
{
|
|
name: "DID with subdomain",
|
|
input: "did:web:hold01.atcr.io",
|
|
expected: "https://hold01.atcr.io",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := atproto.ResolveHoldURL(tt.input)
|
|
if result != tt.expected {
|
|
t.Errorf("ResolveHoldURL(%q) = %q, want %q", tt.input, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|