package opensuse
import (
"strings"
"testing"
"tangled.org/odd.computer/isomorph/internal/distro"
)
const primaryXML = `
json-csrc
https://github.com/json-c/json-c/wiki
libjson-c5x86_64
https://github.com/json-c/json-c/wikijson-c-0.18-1.2.src.rpm
atsrc
`
func TestParsePrimary(t *testing.T) {
got, err := ParsePrimary(strings.NewReader(primaryXML))
if err != nil {
t.Fatal(err)
}
if len(got) != 3 || got[0] != (RPM{Name: "json-c", Arch: "src", Version: "0.18-1.2", URL: "https://github.com/json-c/json-c/wiki"}) ||
got[1].SourceRPM != "json-c-0.18-1.2.src.rpm" || got[2].Version != "1:3.2-4" {
t.Fatalf("ParsePrimary = %+v", got)
}
for in, want := range map[string]string{"json-c-0.18-1.2.src.rpm": "json-c", "python-foo-bar-1.0-3.1.src.rpm": "python-foo-bar", "x.src.rpm": ""} {
if got := SourceName(in); got != want {
t.Errorf("SourceName(%q) = %q, want %q", in, got, want)
}
}
if !primaryHrefRe.MatchString(`ab`) {
t.Error("repomd primary href not found")
}
}
func TestGitHubPagesHomepage(t *testing.T) {
for in, want := range map[string]string{
"https://blueobelisk.github.io/datarepository.html": "https://github.com/blueobelisk/blueobelisk.github.io",
"https://foo.github.io/bar/": "https://github.com/foo/bar",
} {
if got, _, ok := distro.MapHost(in); !ok || got != want {
t.Errorf("MapHost(%q) = %q %v, want %q", in, got, ok, want)
}
}
}