Add test for reading pacman config

This commit is contained in:
morganamilo 2018-09-10 21:25:38 +01:00
parent b2f636d93b
commit 7251ffac8a
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 88 additions and 0 deletions

61
config_test.go Normal file
View file

@ -0,0 +1,61 @@
package main
import (
"reflect"
"testing"
)
func expect(t *testing.T, field string, a interface{}, b interface{}, err error) {
if err != nil {
t.Error(err)
} else if !reflect.DeepEqual(a, b) {
t.Errorf("%s expected: %s got %s", field, a, b)
}
}
func TestConfig(t *testing.T) {
config.PacmanConf = "/home/morganamilo/git/yay/testdata/pacman.conf"
err := initAlpm()
if err != nil {
t.Fatal(err)
}
h := alpmHandle
root, err := h.Root()
expect(t, "RootDir", "/", root, err)
cache, err := h.CacheDirs()
expect(t, "CacheDir", []string{"/cachedir/", "/another/"}, cache.Slice(), err)
log, err := h.LogFile()
expect(t, "LogFile", "/logfile", log, err)
gpg, err := h.GPGDir()
expect(t, "GPGDir", "/gpgdir/", gpg, err)
hook, err := h.HookDirs()
expect(t, "HookDir", []string{"/usr/share/libalpm/hooks/", "/hookdir/"}, hook.Slice(), err)
delta, err := h.DeltaRatio()
expect(t, "UseDelta", 0.5, delta, err)
arch, err := h.Arch()
expect(t, "Architecture", "8086", arch, err)
ignorePkg, err := h.IgnorePkgs()
expect(t, "IgnorePkg", []string{"ignore", "this", "package"}, ignorePkg.Slice(), err)
ignoreGroup, err := h.IgnoreGroups()
expect(t, "IgnoreGroup", []string{"ignore", "this", "group"}, ignoreGroup.Slice(), err)
noUp, err := h.NoUpgrades()
expect(t, "NoUpgrade", []string{"noupgrade"}, noUp.Slice(), err)
noEx, err := h.NoExtracts()
expect(t, "NoExtract", []string{"noextract"}, noEx.Slice(), err)
check, err := h.CheckSpace()
expect(t, "CheckSpace", true, check, err)
}

27
testdata/pacman.conf vendored Normal file
View file

@ -0,0 +1,27 @@
[options]
RootDir = /
CacheDir = /cachedir/ /another/
LogFile = /logfile
GPGDir = /gpgdir/
HookDir = /hookdir/
UseDelta = 0.5
Architecture = 8086
IgnorePkg = ignore
IgnorePkg = this
IgnorePkg = package
IgnoreGroup = ignore
IgnoreGroup = this
IgnoreGroup = group
NoUpgrade = noupgrade
NoExtract = noextract
CheckSpace
TotalDownload
ILoveCandy
VerbosePkgLists
[repo1]
Server = repo1
[repo2]
Server = repo2