beads/cmd/bd/sync_remote_test.go
Andreas Lingenhag 1e76efcfb6
fix: don't normalize user-provided sync.remote URLs (GH#3339) (#3432)
normalizeRemoteURL() converts http:// to git+http://, which breaks Dolt
remotesapi endpoints. Stop normalizing URLs from sync.remote (user
explicitly chose the format) while keeping normalization for auto-detected
git origin URLs. Also add git+http to allowedSchemes in remotecache so
ValidateRemoteURL accepts it.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-24 09:33:02 -07:00

38 lines
1.5 KiB
Go

package main
import "testing"
func TestNormalizeRemoteURL(t *testing.T) {
tests := []struct {
input string
want string
}{
// Dolt-native schemes — returned as-is
{"dolthub://myorg/beads", "dolthub://myorg/beads"},
{"file:///tmp/doltdb", "file:///tmp/doltdb"},
{"aws://[dolt-table:us-east-1]/mydb", "aws://[dolt-table:us-east-1]/mydb"},
{"gs://my-bucket/mydb", "gs://my-bucket/mydb"},
{"git+https://github.com/org/repo.git", "git+https://github.com/org/repo.git"},
{"git+ssh://git@github.com/org/repo.git", "git+ssh://git@github.com/org/repo.git"},
{"git+http://example.com/repo.git", "git+http://example.com/repo.git"},
// Git URLs — converted to dolt remote format
{"https://github.com/org/repo.git", "git+https://github.com/org/repo.git"},
{"http://github.com/org/repo.git", "git+http://github.com/org/repo.git"},
{"ssh://git@github.com/org/repo.git", "git+ssh://git@github.com/org/repo.git"},
{"git@github.com:org/repo.git", "git+ssh://git@github.com/org/repo.git"},
// Dolt remotesapi URLs — also converted (callers that need
// pass-through for user-provided URLs should skip normalization)
{"http://myserver:7007/mydb", "git+http://myserver:7007/mydb"},
{"https://doltremoteapi.example.com/mydb", "git+https://doltremoteapi.example.com/mydb"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := normalizeRemoteURL(tt.input)
if got != tt.want {
t.Errorf("normalizeRemoteURL(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}