2020-08-16 23:41:38 +02:00
|
|
|
package ialpm
|
2020-08-16 22:54:48 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-07-03 18:12:17 +02:00
|
|
|
alpm "github.com/Jguer/go-alpm/v2"
|
2020-08-16 22:54:48 +02:00
|
|
|
"github.com/Morganamilo/go-pacmanconf"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAlpmExecutor(t *testing.T) {
|
2020-08-21 02:39:52 +02:00
|
|
|
pacmanConf := &pacmanconf.Config{
|
|
|
|
RootDir: "/",
|
2020-08-16 22:54:48 +02:00
|
|
|
DBPath: "/var/lib/pacman/",
|
|
|
|
CacheDir: []string{"/cachedir/", "/another/"},
|
|
|
|
HookDir: []string{"/hookdir/"},
|
|
|
|
GPGDir: "/gpgdir/",
|
|
|
|
LogFile: "/logfile",
|
|
|
|
HoldPkg: []string(nil),
|
|
|
|
IgnorePkg: []string{"ignore", "this", "package"},
|
|
|
|
IgnoreGroup: []string{"ignore", "this", "group"},
|
2021-05-02 15:46:41 +02:00
|
|
|
Architecture: []string{"8086"},
|
2020-08-16 22:54:48 +02:00
|
|
|
XferCommand: "",
|
|
|
|
NoUpgrade: []string{"noupgrade"},
|
|
|
|
NoExtract: []string{"noextract"},
|
|
|
|
CleanMethod: []string{"KeepInstalled"},
|
|
|
|
SigLevel: []string{"PackageOptional", "PackageTrustedOnly", "DatabaseOptional", "DatabaseTrustedOnly"},
|
|
|
|
LocalFileSigLevel: []string(nil),
|
|
|
|
RemoteFileSigLevel: []string(nil),
|
|
|
|
UseSyslog: false,
|
|
|
|
Color: false,
|
|
|
|
UseDelta: 0,
|
|
|
|
TotalDownload: true,
|
|
|
|
CheckSpace: true,
|
|
|
|
VerbosePkgLists: true,
|
|
|
|
DisableDownloadTimeout: false,
|
|
|
|
Repos: []pacmanconf.Repository{
|
|
|
|
{Name: "repo1", Servers: []string{"repo1"}, SigLevel: []string(nil), Usage: []string{"All"}},
|
2020-08-21 02:39:52 +02:00
|
|
|
{Name: "repo2", Servers: []string{"repo2"}, SigLevel: []string(nil), Usage: []string{"All"}},
|
|
|
|
},
|
|
|
|
}
|
2020-08-16 22:54:48 +02:00
|
|
|
|
2020-08-16 23:41:38 +02:00
|
|
|
aExec, err := NewExecutor(pacmanConf)
|
2020-08-16 22:54:48 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.NotNil(t, aExec.conf)
|
|
|
|
assert.EqualValues(t, pacmanConf, aExec.conf)
|
|
|
|
|
|
|
|
assert.NotNil(t, aExec.localDB)
|
|
|
|
assert.NotNil(t, aExec.syncDB)
|
|
|
|
assert.NotNil(t, aExec.questionCallback)
|
|
|
|
h := aExec.handle
|
|
|
|
assert.NotNil(t, h)
|
|
|
|
|
|
|
|
root, err := h.Root()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "/", root)
|
|
|
|
|
|
|
|
dbPath, err := h.DBPath()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "/var/lib/pacman/", dbPath)
|
|
|
|
|
|
|
|
cache, err := h.CacheDirs()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, []string{"/cachedir/", "/another/"}, cache.Slice())
|
|
|
|
|
|
|
|
log, err := h.LogFile()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "/logfile", log)
|
|
|
|
|
|
|
|
gpg, err := h.GPGDir()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "/gpgdir/", gpg)
|
|
|
|
|
|
|
|
hook, err := h.HookDirs()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, []string{"/usr/share/libalpm/hooks/", "/hookdir/"}, hook.Slice())
|
|
|
|
|
2021-05-02 15:46:41 +02:00
|
|
|
arch, err := alpmTestGetArch(h)
|
2020-08-16 22:54:48 +02:00
|
|
|
assert.Nil(t, err)
|
2021-05-02 15:46:41 +02:00
|
|
|
assert.Equal(t, []string{"8086"}, arch)
|
2020-08-16 22:54:48 +02:00
|
|
|
|
|
|
|
ignorePkg, err := h.IgnorePkgs()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, []string{"ignore", "this", "package"}, ignorePkg.Slice())
|
|
|
|
|
|
|
|
ignoreGroup, err := h.IgnoreGroups()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, []string{"ignore", "this", "group"}, ignoreGroup.Slice())
|
|
|
|
|
|
|
|
noUp, err := h.NoUpgrades()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, []string{"noupgrade"}, noUp.Slice())
|
|
|
|
|
|
|
|
noEx, err := h.NoExtracts()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, []string{"noextract"}, noEx.Slice())
|
|
|
|
|
|
|
|
check, err := h.CheckSpace()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, true, check)
|
|
|
|
}
|
2021-07-03 18:12:17 +02:00
|
|
|
|
|
|
|
func alpmTestGetArch(h *alpm.Handle) ([]string, error) {
|
|
|
|
architectures, err := h.GetArchitectures()
|
|
|
|
|
|
|
|
return architectures.Slice(), err
|
|
|
|
}
|