forked from oleiade/trousseau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade_test.go
100 lines (83 loc) · 2.66 KB
/
upgrade_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
package trousseau
import (
"encoding/json"
"github.com/oleiade/serrure/openpgp"
"testing"
)
func TestIsVersionZeroDotThree(t *testing.T) {
data := []byte(openpgp.PGP_MESSAGE_HEADER +
"12kjd091jd192jd0192jd" +
openpgp.PGP_MESSAGE_FOOTER)
assert(t,
isVersionZeroDotThreeDotZero(data) == true,
"Input test data were suppose to match version 0.3.N")
}
func TestIsVersionZeroDotThree_fails_with_data_shorter_than_pgp_header(t *testing.T) {
data := []byte("abc123")
assert(t,
isVersionZeroDotThreeDotZero(data) == false,
"Input test data weren't suppose to match version 0.3.N")
}
func TestIsVersionZeroDotFour(t *testing.T) {
store := map[string]interface{}{
"crypto_algorithm": 0,
"crypto_type": 1,
"_data": "oqwimdoqiwmd0qwd0iq0wdijqw9d0",
}
data, err := json.Marshal(store)
if err != nil {
t.Error(err)
}
assert(t,
isVersionZeroDotThreeDotOne(data) == true,
"Input test data were suppose to match version 0.4.N")
}
func TestDiscoverVersion_with_only_one_valid_version_in_mapping(t *testing.T) {
var data []byte = []byte(openpgp.PGP_MESSAGE_HEADER +
"12kjd091jd192jd0192jd" +
openpgp.PGP_MESSAGE_FOOTER)
var mapping map[string]VersionMatcher = map[string]VersionMatcher{
"0.3.0": isVersionZeroDotThreeDotZero,
}
assert(t,
DiscoverVersion(data, mapping) == "0.3.0",
"Version 0.3.0 was supposed to be discovered")
}
func TestDiscoverVersion_with_two_valid_versions_in_mapping(t *testing.T) {
var store map[string]interface{} = map[string]interface{}{
"crypto_algorithm": 0,
"crypto_type": 1,
"_data": "oqwimdoqiwmd0qwd0iq0wdijqw9d0",
}
var mapping map[string]VersionMatcher = map[string]VersionMatcher{
"0.3.0": isVersionZeroDotThreeDotZero,
"0.4.0": isVersionZeroDotThreeDotOne,
}
data, err := json.Marshal(store)
if err != nil {
t.Error(err)
}
assert(t,
DiscoverVersion(data, mapping) == "0.4.0",
"Version 0.4.0 was supposed to be discovered")
}
func TestDiscoverVersion_with_two_matching_version_returns_the_lowest(t *testing.T) {
var data []byte = []byte(openpgp.PGP_MESSAGE_HEADER +
"12kjd091jd192jd0192jd" +
openpgp.PGP_MESSAGE_FOOTER)
var mapping map[string]VersionMatcher = map[string]VersionMatcher{
"0.3.0": isVersionZeroDotThreeDotZero,
"0.3.1": isVersionZeroDotThreeDotZero,
}
assert(t,
DiscoverVersion(data, mapping) == "0.3.0",
"Version 0.3.0 was supposed to be discovered")
}
func TestDiscoverVersion_with_no_matching_version(t *testing.T) {
var data []byte = []byte("abc")
var mapping map[string]VersionMatcher = map[string]VersionMatcher{
"0.3.0": isVersionZeroDotThreeDotZero,
"0.4.0": isVersionZeroDotThreeDotOne,
}
equals(t, DiscoverVersion(data, mapping), "")
}