forked from mrosset/go-alpm
-
Notifications
You must be signed in to change notification settings - Fork 4
/
package_test.go
83 lines (71 loc) · 1.99 KB
/
package_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
76
77
78
79
80
81
82
83
package alpm
import (
"bytes"
"fmt"
"testing"
"text/template"
"time"
)
// Auxiliary formatting
const pkginfo_template = `
Name : {{ .Name }}
Version : {{ .Version }}
Architecture : {{ .Architecture }}
Description : {{ .Description }}
URL : {{ .URL }}
Groups : {{ .Groups.Slice }}
Licenses : {{ .Licenses.Slice }}
Dependencies : {{ range .Depends.Slice }}{{ . }} {{ end }}
Provides : {{ range .Provides.Slice }}{{ . }} {{ end }}
Replaces : {{ range .Replaces.Slice }}{{ . }} {{ end }}
Conflicts : {{ range .Conflicts.Slice }}{{ . }} {{ end }}
Packager : {{ .Packager }}
Build Date : {{ .PrettyBuildDate }}
Install Date : {{ .PrettyInstallDate }}
Package Size : {{ .Size }} bytes
Install Size : {{ .ISize }} bytes
MD5 Sum : {{ .MD5Sum }}
SHA256 Sum : {{ .SHA256Sum }}
Reason : {{ .Reason }}
Required By : {{ .ComputeRequiredBy }}
Files : {{ range .Files }}
{{ .Name }} {{ .Size }}{{ end }}
`
var pkginfo_tpl *template.Template
type PrettyPackage struct {
Package
}
func (p PrettyPackage) PrettyBuildDate() string {
return p.BuildDate().Format(time.RFC1123)
}
func (p PrettyPackage) PrettyInstallDate() string {
return p.InstallDate().Format(time.RFC1123)
}
func init() {
var er error
pkginfo_tpl, er = template.New("info").Parse(pkginfo_template)
if er != nil {
fmt.Printf("couldn't compile template: %s\n", er)
panic("template parsing error")
}
}
// Tests package attribute getters.
func TestPkginfo(t *testing.T) {
h, er := Init(root, dbpath)
defer h.Release()
if er != nil {
t.Errorf("Failed at alpm initialization: %s", er)
}
t.Log("Printing package information for pacman")
db, _ := h.LocalDb()
pkg, _ := db.PkgByName("pacman")
buf := bytes.NewBuffer(nil)
pkginfo_tpl.Execute(buf, PrettyPackage{*pkg})
t.Logf("%s...", buf.Bytes()[:1024])
pkg, _ = db.PkgByName("linux")
if pkg != nil {
buf = bytes.NewBuffer(nil)
pkginfo_tpl.Execute(buf, PrettyPackage{*pkg})
t.Logf("%s...", buf.Bytes()[:1024])
}
}