forked from remyoudompheng/go-alpm
-
Notifications
You must be signed in to change notification settings - Fork 14
/
alpm_test.go
75 lines (61 loc) · 1.31 KB
/
alpm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// alpm_test.go - Tests for alpm.go.
//
// Copyright (c) 2013 The go-alpm Authors
//
// MIT Licensed. See LICENSE for details.
package alpm_test
import (
"testing"
"github.com/stretchr/testify/assert"
alpm "github.com/Jguer/go-alpm/v2"
)
const (
root = "/"
dbpath = "/var/lib/pacman"
)
func TestExampleVerCmp(t *testing.T) {
t.Parallel()
assert.Less(t, alpm.VerCmp("1.0-2", "2.0-1"), 0)
assert.Equal(t, alpm.VerCmp("2.0.2-2", "2.0.2-2"), 0)
assert.Greater(t, alpm.VerCmp("1:1.0-2", "2.0-1"), 0)
}
func TestRevdeps(t *testing.T) {
t.Parallel()
h, _ := alpm.Initialize(root, dbpath)
db, _ := h.LocalDB()
pkg := db.Pkg("glibc")
for i, pkgname := range pkg.ComputeRequiredBy() {
t.Logf(pkgname)
if i == 10 {
t.Logf("and %d more...", len(pkg.ComputeRequiredBy())-10)
return
}
}
}
func TestLocalDB(t *testing.T) {
t.Parallel()
h, _ := alpm.Initialize(root, dbpath)
defer func() {
if recover() != nil {
t.Errorf("local db failed")
}
}()
db, _ := h.LocalDB()
number := 0
for _, pkg := range db.PkgCache().Slice() {
number++
if number <= 15 {
t.Logf("%v", pkg.Name())
}
}
if number > 15 {
t.Logf("%d more packages...", number-15)
}
}
func TestRelease(t *testing.T) {
t.Parallel()
h, _ := alpm.Initialize(root, dbpath)
if err := h.Release(); err != nil {
t.Error(err)
}
}