eclipse/lib/gitcache/url_ns_test.go

49 lines
991 B
Go
Raw Normal View History

// 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)
2024-01-28 18:30:19 +00:00
ns, ok := gitcache.URL2NS(url)
if !ok {
return
}
t.Logf("ns = %q", ns)
2024-01-28 18:30:19 +00:00
url2, ok := gitcache.NS2URL(ns)
assert.True(t, ok)
assert.Equal(t, gitcache.NormalizeURL(url), url2)
})
}
func FuzzURL2NS(f *testing.F) {
f.Fuzz(func(t *testing.T, url string) {
2024-01-28 18:30:19 +00:00
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())
})
}
2024-01-28 18:30:19 +00:00
func FuzzNS2URL(f *testing.F) {
f.Fuzz(func(t *testing.T, ns string) {
t.Logf("ns = %q", ns)
_, _ = gitcache.NS2URL(ns)
})
}