|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -import unittest |
16 | | - |
17 | 15 | import os |
18 | | - |
19 | 16 | import time |
20 | | - |
| 17 | +import unittest |
21 | 18 | from unittest.mock import Mock, call |
22 | 19 |
|
23 | | -from kubernetes import client,config |
| 20 | +from kubernetes import client, config |
| 21 | +from kubernetes.client import ApiException |
24 | 22 |
|
25 | 23 | from .watch import Watch |
26 | 24 |
|
27 | | -from kubernetes.client import ApiException |
28 | | - |
29 | 25 |
|
30 | 26 | class WatchTests(unittest.TestCase): |
31 | 27 | def setUp(self): |
@@ -392,9 +388,22 @@ def test_unmarshal_with_bookmark(self): |
392 | 388 | '"metadata":{},"spec":{"containers":null}}},"status":{}}}', |
393 | 389 | 'V1Job') |
394 | 390 | self.assertEqual("BOOKMARK", event['type']) |
395 | | - # Watch.resource_version is *not* updated, as BOOKMARK is treated the |
396 | | - # same as ERROR for a quick fix of decoding exception, |
397 | | - # resource_version in BOOKMARK is *not* used at all. |
| 391 | + self.assertEqual("1", w.resource_version) |
| 392 | + |
| 393 | + def test_unmarshal_with_bookmark_metadata_not_in_dict(self): |
| 394 | + w = Watch() |
| 395 | + event = w.unmarshal_event( |
| 396 | + '{"type":"BOOKMARK","object":{"metadata": "not-a-dict"}}', |
| 397 | + 'V1Job') |
| 398 | + self.assertEqual("BOOKMARK", event['type']) |
| 399 | + self.assertEqual(None, w.resource_version) |
| 400 | + |
| 401 | + def test_unmarshal_with_bookmark_metadata_without_resource_version(self): |
| 402 | + w = Watch() |
| 403 | + event = w.unmarshal_event( |
| 404 | + '{"type":"BOOKMARK","object":{"metadata": {"name": "foo"}}}', |
| 405 | + 'V1Job') |
| 406 | + self.assertEqual("BOOKMARK", event['type']) |
398 | 407 | self.assertEqual(None, w.resource_version) |
399 | 408 |
|
400 | 409 | def test_watch_with_exception(self): |
|
0 commit comments