-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_test.py
178 lines (130 loc) · 6.29 KB
/
utils_test.py
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
import client
import unittest
import utils
class MyTestCase(unittest.TestCase):
def setUp(self):
self.all_advisories = [
('https://istio.io/adv1', ['1.0.1 to 1.0.8', '2.0 to 2.1.3', '3.0']),
('https://istio.io/adv2', ['1.0 to 1.0.8']),
('https://istio.io/adv3', ['3.0.4 to 3.0.8', '4.0'])
]
self.eol_versions = [
'1.0',
'1.1',
'1.3'
]
def test_version_range1(self):
self.assertTrue(utils.is_in_version_range("1.5", "1.5"))
def test_version_range2(self):
self.assertTrue(utils.is_in_version_range("1.5", "1.5.0"))
def test_version_range3(self):
self.assertTrue(utils.is_in_version_range("1.5.0", "1.5"))
def test_version_range4(self):
self.assertTrue(utils.is_in_version_range("1.5.0", "1.5"))
def test_version_range5(self):
self.assertFalse(utils.is_in_version_range("2.5", "1.5"))
def test_version_range6(self):
self.assertFalse(utils.is_in_version_range("1.5", "2.5.0"))
def test_version_range7(self):
self.assertFalse(utils.is_in_version_range("1.5.3", "1.5"))
def test_version_range8(self):
self.assertFalse(utils.is_in_version_range("1.5.0", "3.5"))
def test_version_range9(self):
self.assertTrue(utils.is_in_version_range("1.5", "1.0 to 1.5"))
def test_version_range10(self):
self.assertTrue(utils.is_in_version_range("1.5", "1.0 to 1.5.0"))
def test_version_range11(self):
self.assertTrue(utils.is_in_version_range("1.5.0", "1.0 to 1.5.0"))
def test_version_range12(self):
self.assertTrue(utils.is_in_version_range("1.5.0", "1.0 to 1.5"))
def test_version_range13(self):
self.assertFalse(utils.is_in_version_range("1.5.0", "1.0 to 1.4"))
def test_version_range14(self):
self.assertFalse(utils.is_in_version_range("1.5.0", "1.0 to 1.4"))
def test_version_range15(self):
self.assertFalse(utils.is_in_version_range("1.5.0", "2.0 to 2.6.0"))
def test_version_range16(self):
self.assertFalse(utils.is_in_version_range("2.5.0", "1.0 to 1.6.0"))
def test_version_range_all_releases_neg(self):
self.assertFalse(utils.is_in_version_range("2.5.0", "All releases prior to 1.5"))
def test_version_range_all_releases_pos(self):
self.assertTrue(utils.is_in_version_range("1.4.6", "All releases prior to 1.5"))
def test_norm1(self):
major, minor, build = utils.norm_version('1.0.1')
self.assertEqual(major, 1)
self.assertEqual(minor, 0)
self.assertEqual(build, 1)
def test_norm2(self):
major, minor, build = utils.norm_version('126.0.45')
self.assertEqual(major, 126)
self.assertEqual(minor, 0)
self.assertEqual(build, 45)
def test_norm3(self):
major, minor, build = utils.norm_version('11.33')
self.assertEqual(major, 11)
self.assertEqual(minor, 33)
self.assertEqual(build, 0)
def test_norm4(self):
self.assertRaises(ValueError, utils.norm_version,'v.1.4')
def test_norm5(self):
self.assertRaises(ValueError, utils.norm_version,'v.1')
def test_norm_all_releases_prior(self):
major, minor, build = utils.norm_version('All releases prior')
self.assertEqual(major, 0)
self.assertEqual(minor, 0)
self.assertEqual(build, 0)
def test_norm_all_releases_prior_non_stripped(self):
major, minor, build = utils.norm_version(' All releases prior ')
self.assertEqual(major, 0)
self.assertEqual(minor, 0)
self.assertEqual(build, 0)
def test_minor_version_included(self):
self.assertTrue(utils.minor_version_included('1.5.8', '1.5'))
def test_minor_version_included_start(self):
self.assertTrue(utils.minor_version_included('1.5.0', '1.5'))
def test_minor_version_included_end(self):
self.assertFalse(utils.minor_version_included('1.6.0', '1.5'))
def test_minor_version_included_major(self):
self.assertFalse(utils.minor_version_included('2.5.8', '1.5'))
def test_supported_version(self):
self.assertTrue(utils.is_supported_version('0.5', self.eol_versions))
def test_supported_version2(self):
self.assertTrue(utils.is_supported_version('1.5', self.eol_versions))
def test_supported_version3(self):
self.assertTrue(utils.is_supported_version('2.0', self.eol_versions))
def test_supported_version4(self):
self.assertTrue(utils.is_supported_version('1.2', self.eol_versions))
def test_supported_version5(self):
self.assertTrue(utils.is_supported_version('1.2.3', self.eol_versions))
def test_unsupported_version(self):
self.assertFalse(utils.is_supported_version('1.1.3', self.eol_versions))
def test_unsupported_version2(self):
self.assertFalse(utils.is_supported_version('1.1', self.eol_versions))
def test1(self):
advisories = utils.filter_not_applicable_advisories('1.0', self.all_advisories)
self.assertEqual(1, len(advisories))
self.assertEqual('https://istio.io/adv2', advisories[0])
def test2(self):
advisories = utils.filter_not_applicable_advisories('1.0.0', self.all_advisories)
self.assertEqual(1, len(advisories))
self.assertEqual('https://istio.io/adv2', advisories[0])
def test3(self):
advisories = utils.filter_not_applicable_advisories('1.0.1', self.all_advisories)
self.assertEqual(2, len(advisories))
self.assertEqual('https://istio.io/adv1', advisories[0])
self.assertEqual('https://istio.io/adv2', advisories[1])
def test4(self):
advisories = utils.filter_not_applicable_advisories('1.0.9', self.all_advisories)
self.assertEqual(0, len(advisories))
def test5(self):
advisories = utils.filter_not_applicable_advisories('1.5', self.all_advisories)
self.assertEqual(0, len(advisories))
def test6(self):
advisories = utils.filter_not_applicable_advisories('3.0.3', self.all_advisories)
self.assertEqual(0, len(advisories))
def test7(self):
advisories = utils.filter_not_applicable_advisories('3.0.6', self.all_advisories)
self.assertEqual(1, len(advisories))
self.assertEqual('https://istio.io/adv3', advisories[0])
if __name__ == '__main__':
unittest.main()