diff options
| author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2018-07-26 16:34:15 -0300 |
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2018-11-27 20:22:14 -0500 |
| commit | 3e379f6e49e1d4a93f34270a52881e82ea8e7173 (patch) | |
| tree | 73660704b4d8272aaf727d77e3f207e63941152a /tests/topotests/lib/test/test_json.py | |
| parent | a82e5f9a7f56066c6b858a78b1e709e31793ffff (diff) | |
topotests: fix json_cmp wrong list handling
Don't quit on the first match. While here add some more `json_cmp` tests
to make sure this doesn't happen again.
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'tests/topotests/lib/test/test_json.py')
| -rwxr-xr-x | tests/topotests/lib/test/test_json.py | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/tests/topotests/lib/test/test_json.py b/tests/topotests/lib/test/test_json.py index e397194503..3927ba095d 100755 --- a/tests/topotests/lib/test/test_json.py +++ b/tests/topotests/lib/test/test_json.py @@ -329,5 +329,128 @@ def test_json_with_list_failure(): assert json_cmp(dcomplete, dsub2) is not None assert json_cmp(dcomplete, dsub3) is not None + +def test_json_list_start_success(): + "Test JSON encoded data that starts with a list that should succeed." + + dcomplete = [ + { + "id": 100, + "value": "abc", + }, + { + "id": 200, + "value": "abcd", + }, + { + "id": 300, + "value": "abcde", + }, + ] + + dsub1 = [ + { + "id": 100, + "value": "abc", + } + ] + + dsub2 = [ + { + "id": 100, + "value": "abc", + }, + { + "id": 200, + "value": "abcd", + } + ] + + dsub3 = [ + { + "id": 300, + "value": "abcde", + } + ] + + dsub4 = [ + ] + + dsub5 = [ + { + "id": 100, + } + ] + + assert json_cmp(dcomplete, dsub1) is None + assert json_cmp(dcomplete, dsub2) is None + assert json_cmp(dcomplete, dsub3) is None + assert json_cmp(dcomplete, dsub4) is None + assert json_cmp(dcomplete, dsub5) is None + + +def test_json_list_start_failure(): + "Test JSON encoded data that starts with a list that should fail." + + dcomplete = [ + { + "id": 100, + "value": "abc" + }, + { + "id": 200, + "value": "abcd" + }, + { + "id": 300, + "value": "abcde" + }, + ] + + dsub1 = [ + { + "id": 100, + "value": "abcd", + } + ] + + dsub2 = [ + { + "id": 100, + "value": "abc", + }, + { + "id": 200, + "value": "abc", + } + ] + + dsub3 = [ + { + "id": 100, + "value": "abc", + }, + { + "id": 350, + "value": "abcde", + } + ] + + dsub4 = [ + { + "value": "abcx", + }, + { + "id": 300, + "value": "abcde", + } + ] + + assert json_cmp(dcomplete, dsub1) is not None + assert json_cmp(dcomplete, dsub2) is not None + assert json_cmp(dcomplete, dsub3) is not None + assert json_cmp(dcomplete, dsub4) is not None + + if __name__ == '__main__': sys.exit(pytest.main()) |
