-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetadata_test.go
121 lines (113 loc) · 4.49 KB
/
metadata_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package sapt
import (
"reflect"
"strings"
"testing"
)
func TestMetadataFromDeb(t *testing.T) {
want := &packageMetadata{
Filename: "./fixtures/less_458-3_amd64.deb",
Package: "less",
Version: "458-3",
Size: "124466",
Architecture: "amd64",
Maintainer: "Anibal Monsalve Salazar <[email protected]>",
InstalledSize: "253",
Depends: "libc6 (>= 2.14), libtinfo5, debianutils (>= 1.8)",
Section: "text",
Priority: "important",
Homepage: "http://www.greenwoodsoftware.com/less/",
Description: `pager program similar to more
This package provides "less", a file pager (that is, a memory-efficient
utility for displaying text one screenful at a time). Less has many
more features than the basic pager "more". As part of the GNU project,
it is widely regarded as the standard pager on UNIX-derived systems.
.
Also provided are "lessecho", a simple utility for ensuring arguments
with spaces are correctly quoted; "lesskey", a tool for modifying the
standard (vi-like) keybindings; and "lesspipe", a filter for specific
types of input, such as .doc or .txt.gz files.
`,
}
metadata := metadataFromDeb("./fixtures/less_458-3_amd64.deb")
if !reflect.DeepEqual(want, metadata) {
t.Fatalf("not equal\nwant: %+v\ngot: %+v", want, metadata)
}
}
func TestMetadataFromControl(t *testing.T) {
want := &packageMetadata{
Package: "less",
Version: "458-3",
Architecture: "amd64",
Maintainer: "Anibal Monsalve Salazar <[email protected]>",
InstalledSize: "253",
Depends: "libc6 (>= 2.14), libtinfo5, debianutils (>= 1.8)",
Section: "text",
Priority: "important",
Homepage: "http://www.greenwoodsoftware.com/less/",
Description: `pager program similar to more
This package provides "less", a file pager (that is, a memory-efficient
utility for displaying text one screenful at a time). Less has many
more features than the basic pager "more". As part of the GNU project,
it is widely regarded as the standard pager on UNIX-derived systems.
.
Also provided are "lessecho", a simple utility for ensuring arguments
with spaces are correctly quoted; "lesskey", a tool for modifying the
standard (vi-like) keybindings; and "lesspipe", a filter for specific
types of input, such as .doc or .txt.gz files.
`,
}
controlOutput := `Package: less
Version: 458-3
Architecture: amd64
Maintainer: Anibal Monsalve Salazar <[email protected]>
Installed-Size: 253
Depends: libc6 (>= 2.14), libtinfo5, debianutils (>= 1.8)
Section: text
Priority: important
Multi-Arch: foreign
Homepage: http://www.greenwoodsoftware.com/less/
Description: pager program similar to more
This package provides "less", a file pager (that is, a memory-efficient
utility for displaying text one screenful at a time). Less has many
more features than the basic pager "more". As part of the GNU project,
it is widely regarded as the standard pager on UNIX-derived systems.
.
Also provided are "lessecho", a simple utility for ensuring arguments
with spaces are correctly quoted; "lesskey", a tool for modifying the
standard (vi-like) keybindings; and "lesspipe", a filter for specific
types of input, such as .doc or .txt.gz files.
`
metadata := metadataFromControl(strings.Split(controlOutput, "\n"))
if !reflect.DeepEqual(want, metadata) {
t.Fatalf("not equal\nwant: %+v\ngot: %+v", want, metadata)
}
}
func TestMetadataFromHeaders(t *testing.T) {
want := &packageMetadata{
Package: "less",
Version: "458-3",
Architecture: "amd64",
Maintainer: "Anibal Monsalve Salazar <[email protected]>",
InstalledSize: "253",
Depends: "libc6 (>= 2.14), libtinfo5, debianutils (>= 1.8)",
Section: "text",
Priority: "important",
Homepage: "http://www.greenwoodsoftware.com/less/",
}
headers := map[string][]string{
"X-Amz-Meta-Package": []string{"less"},
"X-Amz-Meta-Version": []string{"458-3"},
"X-Amz-Meta-Architecture": []string{"amd64"},
"X-Amz-Meta-Maintainer": []string{"Anibal Monsalve Salazar <[email protected]>"},
"X-Amz-Meta-Installed-Size": []string{"253"},
"X-Amz-Meta-Depends": []string{"libc6 (>= 2.14), libtinfo5, debianutils (>= 1.8)"},
"X-Amz-Meta-Section": []string{"text"},
"X-Amz-Meta-Priority": []string{"important"},
"X-Amz-Meta-Homepage": []string{"http://www.greenwoodsoftware.com/less/"},
}
metadata := metadataFromHeaders(headers)
if !reflect.DeepEqual(want, metadata) {
t.Fatalf("not equal\nwant: %+v\ngot: %+v", want, metadata)
}
}