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.
 

192 lines
5.8 KiB

package archlinux
import (
"bytes"
"io/ioutil"
"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) {
if err := testWritePackageInfo.WritePackageInfo(ioutil.Discard); err != nil {
t.Fatal(err)
}
}
var (
testWritePackageInfo = &Package{
Name: "imagemagick",
Base: "imagemagick",
Version: "6.9.9.15",
Release: "1",
Description: "An image viewing/manipulation program",
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),
Packager: "Antonio Rojas <arojas@archlinux.org>",
}
)