1
0
mirror of https://github.com/Jguer/yay synced 2024-07-09 04:46:19 +00:00
yay/config_test.go
2019-10-22 10:41:53 +01:00

60 lines
1.4 KiB
Go

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 = &Configuration{}
config.PacmanConf = "./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)
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)
}