2018-09-10 20:25:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2020-07-05 13:34:27 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-09-10 20:25:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 00:46:48 +00:00
|
|
|
func TestInitAlpm(t *testing.T) {
|
2020-07-05 14:58:35 +00:00
|
|
|
alpmHandle, pacmanConf, err := initAlpm("testdata/pacman.conf")
|
2020-07-05 13:34:27 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, pacmanConf)
|
2018-09-10 20:25:38 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|