Revision 1d466a4f test/ganeti.utils_unittest.py
b/test/ganeti.utils_unittest.py | ||
---|---|---|
38 | 38 |
import OpenSSL |
39 | 39 |
import warnings |
40 | 40 |
import distutils.version |
41 |
import glob |
|
41 | 42 |
|
42 | 43 |
import ganeti |
43 | 44 |
import testutils |
... | ... | |
513 | 514 |
None) |
514 | 515 |
|
515 | 516 |
|
517 |
class TestTimestampForFilename(unittest.TestCase): |
|
518 |
def test(self): |
|
519 |
self.assert_("." not in utils.TimestampForFilename()) |
|
520 |
self.assert_(":" not in utils.TimestampForFilename()) |
|
521 |
|
|
522 |
|
|
523 |
class TestCreateBackup(testutils.GanetiTestCase): |
|
524 |
def setUp(self): |
|
525 |
testutils.GanetiTestCase.setUp(self) |
|
526 |
|
|
527 |
self.tmpdir = tempfile.mkdtemp() |
|
528 |
|
|
529 |
def tearDown(self): |
|
530 |
testutils.GanetiTestCase.tearDown(self) |
|
531 |
|
|
532 |
shutil.rmtree(self.tmpdir) |
|
533 |
|
|
534 |
def testEmpty(self): |
|
535 |
filename = utils.PathJoin(self.tmpdir, "config.data") |
|
536 |
utils.WriteFile(filename, data="") |
|
537 |
bname = utils.CreateBackup(filename) |
|
538 |
self.assertFileContent(bname, "") |
|
539 |
self.assertEqual(len(glob.glob("%s*" % filename)), 2) |
|
540 |
utils.CreateBackup(filename) |
|
541 |
self.assertEqual(len(glob.glob("%s*" % filename)), 3) |
|
542 |
utils.CreateBackup(filename) |
|
543 |
self.assertEqual(len(glob.glob("%s*" % filename)), 4) |
|
544 |
|
|
545 |
fifoname = utils.PathJoin(self.tmpdir, "fifo") |
|
546 |
os.mkfifo(fifoname) |
|
547 |
self.assertRaises(errors.ProgrammerError, utils.CreateBackup, fifoname) |
|
548 |
|
|
549 |
def testContent(self): |
|
550 |
bkpcount = 0 |
|
551 |
for data in ["", "X", "Hello World!\n" * 100, "Binary data\0\x01\x02\n"]: |
|
552 |
for rep in [1, 2, 10, 127]: |
|
553 |
testdata = data * rep |
|
554 |
|
|
555 |
filename = utils.PathJoin(self.tmpdir, "test.data_") |
|
556 |
utils.WriteFile(filename, data=testdata) |
|
557 |
self.assertFileContent(filename, testdata) |
|
558 |
|
|
559 |
for _ in range(3): |
|
560 |
bname = utils.CreateBackup(filename) |
|
561 |
bkpcount += 1 |
|
562 |
self.assertFileContent(bname, testdata) |
|
563 |
self.assertEqual(len(glob.glob("%s*" % filename)), 1 + bkpcount) |
|
564 |
|
|
565 |
|
|
516 | 566 |
class TestFormatUnit(unittest.TestCase): |
517 | 567 |
"""Test case for the FormatUnit function""" |
518 | 568 |
|
Also available in: Unified diff