-
Notifications
You must be signed in to change notification settings - Fork 1
/
changes_test.go
179 lines (165 loc) · 7.13 KB
/
changes_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package main
import (
"encoding/hex"
"reflect"
"strings"
"testing"
"time"
)
var testParseDebianChanges = []struct {
s string
err string
expect ChangesFile
}{
{testChangesInvalid, "Invalid input", ChangesFile{}},
{testChangesMissing, "Missing field", ChangesFile{}},
{testChanges1, "", testChanges1Result},
{testChanges2, "", testChanges1Result},
}
func TestParseDebianChanges(t *testing.T) {
for i, tt := range testParseDebianChanges {
c, err := ParseDebianChanges(strings.NewReader(tt.s), nil)
if err == nil {
c.Control = ControlFile{}
if !reflect.DeepEqual(tt.expect, c) {
t.Errorf("%d. failed:\n got: %+v\n expected: %+v\n", i, c, tt.expect)
}
} else {
if tt.err == "" {
t.Errorf("%d. failed: %q\n", i, err.Error())
}
}
}
}
var testChangesInvalid = `Just some random malformed rubbish`
var testChangesMissing = `Format: 1.8
Date: Fri, 28 Nov 2014 12:00:50 +0000
Version: 1.0.0
Distribution: UNRELEASED
Description:
whacky-package - Acme Whacky Web Site
Files:
76ec08542b9e2aeba4d6f144d861ec6d 10091104 utils extra whacky-package-assets-1417610953_1.0.0_amd64.deb`
var testChanges1 = `Format: 1.8
Date: Fri, 28 Nov 2014 12:00:50 +0000
Source: whacky-package (1.0.0-1)
Binary: whacky-package whacky-package-assets whacky-package-assets-1417610953
Architecture: source amd64
Version: 1.0.0-2
Distribution: UNRELEASED
Urgency: low
Maintainer: Tristan Colgate-McFarlane <[email protected]>
Changed-By: michael <[email protected]>
Description:
whacky-package - Acme Whacky Web Site
whacky-package-assets - Virtual package for Acme Whacky Web Site Assets
whacky-package-assets-1417610953 - Acme Whacky Web Site Assets
Changes:
whacky-package (1.0.0) UNRELEASED; urgency=low
.
* Initial release.
Checksums-Sha1:
3c74c3f289c51f85237fcd40e5d8c4371c33cfe3 744 whacky-package_1.0.0.dsc
778f77115127a934afbf1d2ac7086eaeb3adced9 38524512 whacky-package_1.0.0.tar.gz
455f8c36ffa6d09c9b4edd265db04aa4661a1955 54960116 whacky-package_1.0.0_amd64.deb
edb564f5ede2252aa510af0e67bf649c56e6a357 1050 whacky-package-assets_1.0.0_amd64.deb
Checksums-Sha256:
fee3db6b1e065c91fd78647c708167269a4e4cda1a8315f793cc0f9a5fd128bb 744 whacky-package_1.0.0.dsc
7f1df53706f434b762f274c7b1ad84bdb624681350fdbf009f4afff33f1bf5c7 38524512 whacky-package_1.0.0.tar.gz
00846c0d0038cd8927959ea5d3c5a5b87eb7c76a74178e0dd7fd8b983be4e201 54960116 whacky-package_1.0.0_amd64.deb
23cfa1d5f5c7bd392278472343d01cf05f9d462d834c92a48ff0c44ecf6b7932 1050 whacky-package-assets_1.0.0_amd64.deb
Files:
2c41fac0eea1b8418ee6e1017aa86851 744 utils extra whacky-package_1.0.0.dsc
2ff43945d0c4610f79dd23146708f196 38524512 utils extra whacky-package_1.0.0.tar.gz
3d64879e2934e24fd8c4a4b2a379bb8d 54960116 utils extra whacky-package_1.0.0_amd64.deb
eec26a9aac712cb265dde5faf079ab26 1050 utils extra whacky-package-assets_1.0.0_amd64.deb`
var testChanges1Result = (func() ChangesFile {
f1md5, _ := hex.DecodeString("2c41fac0eea1b8418ee6e1017aa86851")
f2md5, _ := hex.DecodeString("2ff43945d0c4610f79dd23146708f196")
f3md5, _ := hex.DecodeString("3d64879e2934e24fd8c4a4b2a379bb8d")
f4md5, _ := hex.DecodeString("eec26a9aac712cb265dde5faf079ab26")
f1sha1, _ := hex.DecodeString("3c74c3f289c51f85237fcd40e5d8c4371c33cfe3")
f2sha1, _ := hex.DecodeString("778f77115127a934afbf1d2ac7086eaeb3adced9")
f3sha1, _ := hex.DecodeString("455f8c36ffa6d09c9b4edd265db04aa4661a1955")
f4sha1, _ := hex.DecodeString("edb564f5ede2252aa510af0e67bf649c56e6a357")
f1sha256, _ := hex.DecodeString("fee3db6b1e065c91fd78647c708167269a4e4cda1a8315f793cc0f9a5fd128bb")
f2sha256, _ := hex.DecodeString("7f1df53706f434b762f274c7b1ad84bdb624681350fdbf009f4afff33f1bf5c7")
f3sha256, _ := hex.DecodeString("00846c0d0038cd8927959ea5d3c5a5b87eb7c76a74178e0dd7fd8b983be4e201")
f4sha256, _ := hex.DecodeString("23cfa1d5f5c7bd392278472343d01cf05f9d462d834c92a48ff0c44ecf6b7932")
date, _ := time.Parse("Mon, 02 Jan 2006 15:04:05 -0700", "Fri, 28 Nov 2014 12:00:50 +0000")
return ChangesFile{
Date: date,
Architectures: []string{"source", "amd64"},
Binaries: []string{"whacky-package", "whacky-package-assets", "whacky-package-assets-1417610953"},
BinaryVersion: MustParseDebVersion("1.0.0-2"),
Source: "whacky-package",
SourceVersion: MustParseDebVersion("1.0.0-1"),
FileHashes: ChangesFilesHashMap{
ChangesFilesIndex{Name: "whacky-package_1.0.0.dsc", Size: 744}: ChangesFilesHashSet{
"md5": f1md5,
"sha1": f1sha1,
"sha256": f1sha256,
},
ChangesFilesIndex{Name: "whacky-package_1.0.0.tar.gz", Size: 38524512}: ChangesFilesHashSet{
"md5": f2md5,
"sha1": f2sha1,
"sha256": f2sha256,
},
ChangesFilesIndex{Name: "whacky-package_1.0.0_amd64.deb", Size: 54960116}: ChangesFilesHashSet{
"md5": f3md5,
"sha1": f3sha1,
"sha256": f3sha256,
},
ChangesFilesIndex{Name: "whacky-package-assets_1.0.0_amd64.deb", Size: 1050}: ChangesFilesHashSet{
"md5": f4md5,
"sha1": f4sha1,
"sha256": f4sha256,
},
},
}
})()
var testChanges2 = `-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Format: 1.8
Date: Fri, 28 Nov 2014 12:00:50 +0000
Source: whacky-package (1.0.0-1)
Binary: whacky-package whacky-package-assets whacky-package-assets-1417610953
Architecture: source amd64
Version: 1.0.0-2
Distribution: UNRELEASED
Urgency: low
Maintainer: Tristan Colgate-McFarlane <[email protected]>
Changed-By: michael <[email protected]>
Description:
whacky-package - Acme Whacky Web Site
whacky-package-assets - Virtual package for Acme Whacky Web Site Assets
whacky-package-assets-1417610953 - Acme Whacky Web Site Assets
Changes:
whacky-package (1.0.0) UNRELEASED; urgency=low
.
* Initial release.
Checksums-Sha1:
3c74c3f289c51f85237fcd40e5d8c4371c33cfe3 744 whacky-package_1.0.0.dsc
778f77115127a934afbf1d2ac7086eaeb3adced9 38524512 whacky-package_1.0.0.tar.gz
455f8c36ffa6d09c9b4edd265db04aa4661a1955 54960116 whacky-package_1.0.0_amd64.deb
edb564f5ede2252aa510af0e67bf649c56e6a357 1050 whacky-package-assets_1.0.0_amd64.deb
Checksums-Sha256:
fee3db6b1e065c91fd78647c708167269a4e4cda1a8315f793cc0f9a5fd128bb 744 whacky-package_1.0.0.dsc
7f1df53706f434b762f274c7b1ad84bdb624681350fdbf009f4afff33f1bf5c7 38524512 whacky-package_1.0.0.tar.gz
00846c0d0038cd8927959ea5d3c5a5b87eb7c76a74178e0dd7fd8b983be4e201 54960116 whacky-package_1.0.0_amd64.deb
23cfa1d5f5c7bd392278472343d01cf05f9d462d834c92a48ff0c44ecf6b7932 1050 whacky-package-assets_1.0.0_amd64.deb
Files:
2c41fac0eea1b8418ee6e1017aa86851 744 utils extra whacky-package_1.0.0.dsc
2ff43945d0c4610f79dd23146708f196 38524512 utils extra whacky-package_1.0.0.tar.gz
3d64879e2934e24fd8c4a4b2a379bb8d 54960116 utils extra whacky-package_1.0.0_amd64.deb
eec26a9aac712cb265dde5faf079ab26 1050 utils extra whacky-package-assets_1.0.0_amd64.deb
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAEBAgAGBQJUjuXQAAoJEK3l95w8qDsZBDgH/RT5WjnCBwJyTDgztcwFP5xD
i1wTN/tQDx4pYQLv8JLXshKbLUDTEDuMX3HI2i7hTmyAC7DlY7fEnMEZTi/ChY2+
y/ee8qscLXEJmBqD7wArDYWkoBtIl6D5ZeYnOrdbwBJ5bWfZs+ne51ts7f74OrKs
bOVBL3yam9VyhNZgq7Bwy+Ij+szUPGgFKXBMWByRjckkSJT3X4IPSlGArPJEiPI+
7SLYG7cyTH3Ggje/iOZ3SIMdimHljrcFOmk18/Dn5mPj9Fj9wjOaCNE+wcM0KCHB
fe0I0vF5RM/rGCWMSEY/Co1j7BICi3AleOJUQpFtmJhb6A3r1EBc9qJNt1LhyAA=
=p4tl
-----END PGP SIGNATURE-----`