package distro import ( "testing" "tangled.org/odd.computer/isomorph/internal/repourl" ) func TestMapHost(t *testing.T) { cases := []struct { in, want string conf float64 }{ {"https://macosforge.github.io/alac/", "https://github.com/macosforge/alac", 1}, {"http://aranym.github.io", "", 0}, {"https://pagure.io/certmonger", "https://pagure.io/certmonger.git", 1}, {"https://pagure.io/releases/sssd/sssd-2.9.tar.gz", "https://pagure.io/sssd.git", 1}, {"https://cgit.freedesktop.org/xorg/driver/xf86-video-opentegra/", "https://gitlab.freedesktop.org/xorg/driver/xf86-video-opentegra", 1}, {"https://cgit.freedesktop.org/libreoffice/core/tree/README", "https://gitlab.freedesktop.org/libreoffice/core", 1}, {"https://archive.xfce.org/src/apps/gigolo/0.5/gigolo-0.5.2.tar.bz2", "https://gitlab.xfce.org/apps/gigolo", 1}, {"https://www.kernel.org/pub/software/scm/git/git-2.45.tar.xz", "https://git.kernel.org/pub/scm/git/git.git", 1}, {"https://hg.mozilla.org/projects/nspr", "hg+https://hg.mozilla.org/projects/nspr", 1}, {"https://gitlab.linphone.org/BC/public/bcg729/-/archive/1.1/bcg729-1.1.tar.gz", "https://gitlab.linphone.org/BC/public/bcg729.git", 1}, {"https://www.gnu.org/software/tar/", "https://git.savannah.gnu.org/git/tar.git", 0.6}, {"https://www.nongnu.org/zutils/zutils.html", "https://git.savannah.nongnu.org/git/zutils.git", 0.6}, {"https://download.savannah.gnu.org/releases/zutils/zutils-1.13.tar.lz", "https://git.savannah.gnu.org/git/zutils.git", 0.8}, {"https://www.apache.org/dist/apr/apr-1.7.6.tar.bz2", "https://github.com/apache/apr", 0.8}, {"https://archive.apache.org/dist/commons/lang/source/commons-lang3-3.14.0-src.tar.gz", "https://github.com/apache/commons-lang", 0.8}, {"https://downloads.apache.org/apr/KEYS", "https://github.com/apache/apr", 0.8}, {"https://apr.apache.org/", "https://github.com/apache/apr", 0.6}, {"https://docs.xfce.org/apps/ristretto/start", "https://gitlab.xfce.org/apps/ristretto", 0.9}, {"https://docs.xfce.org/panel-plugins/xfce4-places-plugin/start", "https://gitlab.xfce.org/panel-plugins/xfce4-places-plugin", 0.9}, {"https://goodies.xfce.org/projects/panel-plugins/xfce4-places-plugin", "https://gitlab.xfce.org/panel-plugins/xfce4-places-plugin", 0.9}, {"https://docs.xfce.org/apps/start", "", 0}, {"https://www.netfilter.org/projects/libnetfilter_cttimeout/", "https://git.netfilter.org/libnetfilter_cttimeout", 0.9}, {"https://netfilter.org/projects/ulogd/", "https://git.netfilter.org/ulogd2", 0.9}, {"https://freedesktop.org/software/pulseaudio/paprefs/", "https://gitlab.freedesktop.org/pulseaudio/paprefs", 0.9}, {"https://www.freedesktop.org/software/appstream/docs/", "", 0}, {"https://docs.xfce.org/xfce/thunar/archive", "", 0}, {"https://docs.xfce.org/xfce/thunar/start", "https://gitlab.xfce.org/xfce/thunar", 0.9}, {"https://gnupg.org/software/gpa/index.html", "https://git.gnupg.org/gpa.git", 0.9}, {"https://gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.11.2.tar.bz2", "https://git.gnupg.org/libgcrypt.git", 0.9}, {"https://gnupg.org/software/gnupg/index.html", "", 0}, {"https://downloads.python.org/pypy/pypy3.11-v8.0.0-src.tar.gz", "https://github.com/pypy/pypy", 0.9}, {"https://gnu-octave.github.io/packages/geometry/", "", 0}, {"https://ant.apache.org/", "https://github.com/apache/ant", 0.6}, {"https://commons.apache.org/proper/commons-lang/", "", 0}, {"https://www.apache.org/", "", 0}, {"https://curl.se", "", 0}, {"https://github.com/curl/curl", "", 0}, } for _, c := range cases { got, conf, ok := MapHost(c.in) if c.want == "" { if ok { t.Errorf("%s: unexpected mapping %s", c.in, got) } continue } if !ok || got != c.want || conf != c.conf { t.Errorf("%s: got %q %.1f %v, want %q %.1f", c.in, got, conf, ok, c.want, c.conf) continue } if k, err := repourl.RepoKey(got); err != nil || k == "" { t.Errorf("%s: mapped %q is not a repo for repourl: %v", c.in, got, err) } } } func TestIsArchiveURL(t *testing.T) { if !IsArchiveURL("https://x/y-1.tar.gz#/rename.tar.gz") || !IsArchiveURL("https://x/y.zip?download") || IsArchiveURL("https://x/KEYS") { t.Error("archive detection") } }