Browse Source

tests: fill out coverage for new fsck features

tags/nilmdb-2.2.0
Jim Paris 3 years ago
parent
commit
d4003d0d34
9 changed files with 13 additions and 8 deletions
  1. +8
    -8
      nilmdb/fsck/fsck.py
  2. BIN
      tests/fsck-data/test2v/data.sql
  3. BIN
      tests/fsck-data/test2v/data/a/b/0000/0000
  4. +0
    -0
      tests/fsck-data/test2v/data/a/b/_format
  5. BIN
      tests/fsck-data/test2v1/data.sql
  6. BIN
      tests/fsck-data/test2v1/data/a/b/0000/0000
  7. BIN
      tests/fsck-data/test2v2/data.sql
  8. +0
    -0
      tests/fsck-data/test2v2/data/a/b/_format
  9. +5
    -0
      tests/test_fsck.py

+ 8
- 8
nilmdb/fsck/fsck.py View File

@@ -248,23 +248,22 @@ class Fsck(object):

# Check that we can open bulkdata
tab = nilmdb.server.bulkdata.Table(bulk)
except FsckFormatError:
except FsckFormatError as e:
# If there are no files except _format, try deleting
# the entire stream; this may remove metadata, but
# it's probably unimportant.
files = list(os.listdir(bulk))
if len(files) > 1:
raise
if len(files) == 1 and files[0] != b'_format':
raise
raise FsckFormatError(f"{path}: can't load _format, "
f"but data is also present")

# Since the stream was empty, just remove it
self.fix_remove_stream(sid, path, bulk,
"empty, with corrupted format file")
except FsckError:
raise
except Exception as e:
except FsckError as e:
raise e
except Exception as e: # pragma: no cover
# No coverage because this is an unknown/unexpected error
raise FsckError("%s: can't open bulkdata: %s",
path, str(e))
tab.close()
@@ -278,6 +277,7 @@ class Fsck(object):
fmt = pickle.load(f)
except Exception as e:
raise FsckFormatError(f"{path}: can't load _format file ({e})")

if fmt["version"] != 3:
raise FsckFormatError("%s: bad or unsupported bulkdata version %d",
path, fmt["version"])


BIN
tests/fsck-data/test2v/data.sql View File


BIN
tests/fsck-data/test2v/data/a/b/0000/0000 View File


+ 0
- 0
tests/fsck-data/test2v/data/a/b/_format View File


BIN
tests/fsck-data/test2v1/data.sql View File


BIN
tests/fsck-data/test2v1/data/a/b/0000/0000 View File


BIN
tests/fsck-data/test2v2/data.sql View File


+ 0
- 0
tests/fsck-data/test2v2/data/a/b/_format View File


+ 5
- 0
tests/test_fsck.py View File

@@ -163,3 +163,8 @@ class TestFsck(object):
raise Exception("hi")
with assert_raises(Exception):
foo()

self.failmsg("test2v", "can't load _format, but data is also present")
self.failmsg("test2v1", "bad bulkdata table")
self.failmsg("test2v2", "empty, with corrupted format file", fix=False)
self.okmsg("test2v2", "empty, with corrupted format file")

Loading…
Cancel
Save