2024-01-28 05:31:51 +00:00
|
|
|
// Copyright (C) 2024 Umorpha Systems
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
package gitcache_test
|
|
|
|
|
|
|
|
import (
|
2024-01-28 05:56:36 +00:00
|
|
|
"os/exec"
|
2024-01-28 05:31:51 +00:00
|
|
|
"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
|
|
|
|
}
|
2024-01-29 04:04:01 +00:00
|
|
|
nurl, ok := gitcache.NormalizeURL(url)
|
|
|
|
assert.True(t, ok)
|
2024-01-28 05:31:51 +00:00
|
|
|
t.Logf("ns = %q", ns)
|
2024-01-28 18:30:19 +00:00
|
|
|
url2, ok := gitcache.NS2URL(ns)
|
|
|
|
assert.True(t, ok)
|
2024-01-29 04:04:01 +00:00
|
|
|
assert.Equal(t, nurl, url2)
|
2024-01-28 05:56:36 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2024-01-28 05:56:36 +00:00
|
|
|
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 05:31:51 +00:00
|
|
|
})
|
|
|
|
}
|
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)
|
|
|
|
})
|
|
|
|
}
|