Add fs queue backend add file
This commit is contained in:
42
tests/test_fs.py
Normal file
42
tests/test_fs.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import tempfile
|
||||
import shutil
|
||||
import logging
|
||||
import os
|
||||
|
||||
# local imports
|
||||
from chainqueue.fs.cache import FsQueue
|
||||
from chainqueue.fs.dir import HexDir
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class HexDirTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.dir = tempfile.mkdtemp()
|
||||
self.hexdir = HexDir(os.path.join(self.dir, 'q'), 32, 2, 8)
|
||||
self.q = FsQueue(os.path.join(self.dir, 'spool'), backend=self.hexdir)
|
||||
logg.debug('setup fsqueue root {}'.format(self.dir))
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.dir)
|
||||
logg.debug('cleaned fsqueue root {}'.format(self.dir))
|
||||
|
||||
|
||||
def test_new(self):
|
||||
tx_hash = os.urandom(32)
|
||||
tx_content = os.urandom(128)
|
||||
self.q.add(tx_hash, tx_content)
|
||||
|
||||
f = open(os.path.join(self.q.path_state['new'], tx_hash.hex()), 'rb')
|
||||
r = f.read()
|
||||
f.close()
|
||||
self.assertEqual(r, b'\x00' * 8)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -51,6 +51,13 @@ class HexDirTest(unittest.TestCase):
|
||||
self.hexdir.add(label, content, prefix=b'a')
|
||||
|
||||
|
||||
def test_index(self):
|
||||
self.hexdir.add(b'\xde\xad\xbe\xef', b'foo', b'ab')
|
||||
self.hexdir.add(b'\xbe\xef\xfe\xed', b'bar', b'cd')
|
||||
c = self.hexdir.add(b'\x01\x02\x03\x04', b'baz', b'ef')
|
||||
self.assertEqual(c, 2)
|
||||
|
||||
|
||||
def test_edit(self):
|
||||
self.hexdir.add(b'\xde\xad\xbe\xef', b'foo', b'ab')
|
||||
self.hexdir.add(b'\xbe\xef\xfe\xed', b'bar', b'cd')
|
||||
|
||||
Reference in New Issue
Block a user