eclipse/lib/gitcache/url_ns_test.go

51 lines
1.0 KiB
Go

// Copyright (C) 2024 Umorpha Systems
// SPDX-License-Identifier: AGPL-3.0-or-later
package gitcache_test
import (
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"git.mothstuff.lol/lukeshu/eclipse/lib/gitcache"
)
func FuzzRoundTripURL(f *testing.F) {
f.Fuzz(func(t *testing.T, url string) {
t.Logf("url = %q", url)
ns, ok := gitcache.URL2NS(url)
if !ok {
return
}
nurl, ok := gitcache.NormalizeURL(url)
assert.True(t, ok)
t.Logf("ns = %q", ns)
url2, ok := gitcache.NS2URL(ns)
assert.True(t, ok)
assert.Equal(t, nurl, url2)
})
}
func FuzzURL2NS(f *testing.F) {
f.Fuzz(func(t *testing.T, url string) {
t.Logf("url = %q", url)
ns, ok := gitcache.URL2NS(url)
if !ok {
return
}
t.Logf("ns = %q", ns)
assert.False(t, strings.Contains(ns, "/"))
assert.NoError(t, exec.Command("git", "check-ref-format", "refs/"+ns).Run())
})
}
func FuzzNS2URL(f *testing.F) {
f.Fuzz(func(t *testing.T, ns string) {
t.Logf("ns = %q", ns)
_, _ = gitcache.NS2URL(ns)
})
}