diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-10-20 11:58:23 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-10-20 11:58:23 +0300 |
commit | 4f0f9d7cefe096d7f516e6c289e232a5507050b5 (patch) | |
tree | 9ee760443c7cf2853d74982550e7d5a6ec52b7bf | |
parent | c3395677552b8178ae107f5595b8da83f542fb2a (diff) | |
download | muck-poc-4f0f9d7cefe096d7f516e6c289e232a5507050b5.tar.gz |
Add: test-persistence
-rwxr-xr-x | test-persistence | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test-persistence b/test-persistence new file mode 100755 index 0000000..1b5b836 --- /dev/null +++ b/test-persistence @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +# Copyright (C) 2018 Lars Wirzenius +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +import os +import sys + + +import muck + + +def changes(n): + res = { + 'foo': 'bar', + } + + for i in range(n): + meta = { + 'id': 'id-{}'.format(i), + 'rev': 'rev-{}'.format(i), + } + chg = muck.CreateChange(meta=meta, res=res) + yield chg + + +def compare_dicts(d1, d2): + for key in d1: + if key not in d2: + return 'Missing key: {}'.format(key) + + for key in d2: + if key not in d1: + return 'Extra key: {}'.format(key) + + for key in d1: + v1 = d1[key] + v2 = d2[key] + if v1 != v2: + return 'Different values: {}: {} vs {}'.format(key, v1, v2) + + return None + + +store_dir = sys.argv[1] +n = int(sys.argv[2]) + +os.mkdir(store_dir) +st = muck.Store(store_dir) +for i, chg in enumerate(changes(n)): + st.change(chg) + + st2 = muck.Store(store_dir) + ms = st.get_memory_store() + ms2 = st2.get_memory_store() + err = compare_dicts(ms.as_dict(), ms2.as_dict()) + if err: + sys.stderr.write('ERROR: {}: {}\n'.format(i+1, err)) + sys.exit(1) + +sys.stdout.write('OK\n') |