Arch Linux helpers and parsers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

213 lines
6.9 KiB

package archlinux
import (
"bytes"
"encoding/base64"
"io"
"io/ioutil"
"net/url"
"os"
"strings"
"testing"
"time"
)
func TestReadPackageInfo(t *testing.T) {
var tests = []struct {
PKGINFO string
Package
}{
{
testPackageInfo, Package{
Name: "xterm",
Version: "330",
Release: "1",
Arch: []string{"x86_64"},
Size: 851968,
},
},
{
testPackageInfo2, Package{
Name: "imagemagick",
Version: "6.9.9.15",
Release: "1",
Arch: []string{"x86_64"},
Size: 9897984,
},
},
}
for _, test := range tests {
t.Run(test.Package.String(), func(t *testing.T) {
p, err := ReadPackageInfo(bytes.NewBufferString(test.PKGINFO))
if err != nil {
t.Fatal(err)
}
testComparePackage(t, p, &test.Package)
})
}
}
var (
testPackageInfo = `# Generated by makepkg 5.0.2
# using fakeroot version 1.21
# Fri Jun 23 20:03:18 UTC 2017
pkgname = xterm
pkgver = 330-1
pkgdesc = X Terminal Emulator
url = http://invisible-island.net/xterm/
builddate = 1498248198
packager = Andreas Radke <andyrtr@archlinux.org>
size = 851968
arch = x86_64
license = custom
depend = libxft
depend = libxaw
depend = ncurses
depend = xorg-luit
depend = xbitmaps
depend = libutempter
depend = libxkbfile
`
testPackageInfo2 = `# Generated by makepkg 5.0.2
# using fakeroot version 1.22
# Sat Sep 23 21:53:45 UTC 2017
pkgname = imagemagick
pkgbase = imagemagick
pkgver = 6.9.9.15-1
pkgdesc = An image viewing/manipulation program
url = http://www.imagemagick.org/
builddate = 1506203625
packager = Antonio Rojas <arojas@archlinux.org>
size = 9897984
arch = x86_64
license = custom
backup = etc/ImageMagick-6/coder.xml
backup = etc/ImageMagick-6/colors.xml
backup = etc/ImageMagick-6/delegates.xml
backup = etc/ImageMagick-6/log.xml
backup = etc/ImageMagick-6/magic.xml
backup = etc/ImageMagick-6/mime.xml
backup = etc/ImageMagick-6/policy.xml
backup = etc/ImageMagick-6/quantization-table.xml
backup = etc/ImageMagick-6/thresholds.xml
backup = etc/ImageMagick-6/type.xml
backup = etc/ImageMagick-6/type-dejavu.xml
backup = etc/ImageMagick-6/type-ghostscript.xml
backup = etc/ImageMagick-6/type-windows.xml
depend = libltdl
depend = lcms2
depend = libxt
depend = fontconfig
depend = libxext
depend = liblqr
depend = libraqm
depend = opencl-icd-loader
depend = perl>=5.26
depend = perl<5.27
optdepend = imagemagick-doc: for additional information
optdepend = ghostscript: for Ghostscript support
optdepend = openexr: for OpenEXR support
optdepend = openjpeg2: for JP2 support
optdepend = libwmf: for WMF support
optdepend = librsvg: for SVG support
optdepend = libxml2: for XML support
optdepend = libpng: for PNG support
optdepend = libwebp: for WEBP support
optdepend = libraw: for DNG support
makedepend = libltdl
makedepend = lcms2
makedepend = libxt
makedepend = fontconfig
makedepend = libxext
makedepend = ghostscript
makedepend = openexr
makedepend = libwmf
makedepend = librsvg
makedepend = libxml2
makedepend = liblqr
makedepend = openjpeg2
makedepend = libraw
makedepend = libraqm
makedepend = opencl-headers
makedepend = opencl-icd-loader
makedepend = libwebp
makedepend = subversion
makedepend = glu
`
)
func TestReadPackageInfoError(t *testing.T) {
var tests = []struct {
PKGINFO string
Error string
}{
{testPackageInfoError, `unknown PKGINFO field`},
{testPackageInfoErrorName, "name is missing"},
{testPackageInfoErrorVersion, "version is missing"},
//{testPackageInfoErrorVersionInvalid, "invalid version"},
{testPackageInfoErrorRelease, "release is missing"},
}
for _, test := range tests {
t.Run(test.Error, func(t *testing.T) {
_, err := ReadPackageInfo(bytes.NewBufferString(test.PKGINFO))
if err == nil {
t.Fatal("expected error")
}
if s := err.Error(); !strings.Contains(s, test.Error) {
t.Fatalf(`expected error %q, got %q`, test.Error, s)
}
})
}
}
var (
testPackageInfoError = `foo = bar`
testPackageInfoErrorName = `pkgver = 330-1`
testPackageInfoErrorVersion = `pkgname = xterm`
testPackageInfoErrorVersionInvalid = `pkgname = xterm
pkgver = 330`
testPackageInfoErrorRelease = `pkgname = xterm
pkgver = 330-`
)
func TestWritePackageInfo(t *testing.T) {
var w io.Writer
if os.Getenv("TEST_DEBUG_WRITER") != "" {
w = os.Stdout
} else {
w = ioutil.Discard
}
n, err := testWritePackageInfo.WritePackageInfo(w)
if err != nil {
t.Fatal(err)
}
if n == 0 {
t.Fatal(`expected >0 bytes to be written`)
}
t.Log(n, "bytes written")
}
var (
testWritePackageInfoURL, _ = url.Parse("http://www.imagemagick.org/")
testWritePackagePGPSignature, _ = base64.StdEncoding.DecodeString("iQEzBAABCAAdFiEEFRnVq6Zb9vwrc8dWek52CV2KUuQFAlnG2vYACgkQek52CV2KUuTvKAf/XgeeH4ahrRKSvlJYBw2SQ1ZaAYTFv/uc90myNFFO3orRnE+0FBNSR2pHhuXXXpBwalflsVWvtoJzY/0XHU2uLeeWmFGcC5DMqlatlJJgBcIJ+GrQlCqlTonYQ+cK/vdrb7HE3pGEJ+HDx5ye4vsefX1C3ToKXU1D/6r75wF/xIJpRyX8HfZcO4i3IURMjJUGaKu0HklXcvpdR608t/HFDIprk+Oz1BA+QbMIjR0r/hFuxP6wK/e/JckRPDsxV+nOz2dRYDkaWkuiIl1y1wpWWySHh4s17/mWi+BBsG9d6H4/V79ADD1BoggsJDtYO9K5alAivWlACLSPJ1ZQ6yFqlw==")
testWritePackageInfo = &Package{
Name: "imagemagick",
Base: "imagemagick",
Version: "6.9.9.15",
Release: "1",
Description: "An image viewing/manipulation program",
URL: testWritePackageInfoURL,
Arch: []string{"x86_64"},
License: []string{"custom"},
Depends: []string{"libltdl", "lcms2", "libxt", "fontconfig", "libxext", "liblqr", "libraqm", "opencl-icd-loader", "perl>=5.26", "perl<5.27"},
MakeDepends: []string{"libltdl", "lcms2", "libxt", "fontconfig", "libxext", "ghostscript", "openexr", "libwmf", "librsvg", "libxml2", "liblqr", "openjpeg2", "libraw", "libraqm", "opencl-headers", "opencl-icd-loader", "libwebp", "subversion", "glu"},
OptionalDepends: []string{"imagemagick-doc: for additional information", "ghostscript: for Ghostscript support", "openexr: for OpenEXR support", "openjpeg2: for JP2 support", "libwmf: for WMF support", "librsvg: for SVG support", "libxml2: for XML support", "libpng: for PNG support", "libwebp: for WEBP support", "libraw: for DNG support"},
Backup: []string{"etc/ImageMagick-6/coder.xml", "etc/ImageMagick-6/colors.xml", "etc/ImageMagick-6/delegates.xml", "etc/ImageMagick-6/log.xml", "etc/ImageMagick-6/magic.xml", "etc/ImageMagick-6/mime.xml", "etc/ImageMagick-6/policy.xml", "etc/ImageMagick-6/quantization-table.xml", "etc/ImageMagick-6/thresholds.xml", "etc/ImageMagick-6/type.xml", "etc/ImageMagick-6/type-dejavu.xml", "etc/ImageMagick-6/type-ghostscript.xml", "etc/ImageMagick-6/type-windows.xml"},
Size: 9897984,
BuildDate: time.Unix(1506203625, 0),
MD5: []byte("\x54\x71\xa4\x62\x04\xd5\x25\xcb\x3c\x3c\xcf\xc8\x58\x71\x1e\x02"),
SHA256: []byte("\x25\xf5\xfd\x35\x60\x55\xd9\x91\xdc\xb1\x98\x5e\x59\xbd\x65\xb6\x2b\x8a\x14\x34\xb9\x1e\xd4\x94\xea\x99\x2c\x2c\x9e\x53\xe4\xec"),
PGPSignature: testWritePackagePGPSignature,
Packager: "Antonio Rojas <arojas@archlinux.org>",
}
)