Commit 6f1aa78d authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

jstore: Add unittests



Add unittests for FormatJobID, GetArchiveDirectory, ParseJobId.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 526f866b
......@@ -814,6 +814,7 @@ python_tests = \
test/ganeti.hypervisor.hv_xen_unittest.py \
test/ganeti.impexpd_unittest.py \
test/ganeti.jqueue_unittest.py \
test/ganeti.jstore_unittest.py \
test/ganeti.locking_unittest.py \
test/ganeti.luxi_unittest.py \
test/ganeti.masterd.instance_unittest.py \
......
#!/usr/bin/python
#
# Copyright (C) 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Script for testing ganeti.jstore"""
import re
import unittest
import random
from ganeti import constants
from ganeti import utils
from ganeti import compat
from ganeti import errors
from ganeti import jstore
import testutils
class TestFormatJobID(testutils.GanetiTestCase):
def test(self):
self.assertEqual(jstore.FormatJobID(0), "0")
self.assertEqual(jstore.FormatJobID(30498), "30498")
self.assertEqual(jstore.FormatJobID(319472592764518609),
"319472592764518609")
def testErrors(self):
for i in [-1, -2288, -9667, -0.205641, 0.0, 0.1, 13041.4472, "", "Hello",
[], [1], {}]:
self.assertRaises(errors.ProgrammerError, jstore.FormatJobID, i)
class TestGetArchiveDirectory(testutils.GanetiTestCase):
def test(self):
tests = [
("0", [0, 1, 3343, 9712, 9999]),
("1", [10000, 13188, 19999]),
("29", [290000, 296041, 298796, 299999]),
("30", [300000, 309384]),
]
for (exp, job_ids) in tests:
for job_id in job_ids:
fmt_id = jstore.FormatJobID(job_id)
self.assertEqual(jstore.GetArchiveDirectory(fmt_id), exp)
self.assertEqual(jstore.ParseJobId(fmt_id), job_id)
def testErrors(self):
self.assertRaises(errors.ParameterError, jstore.GetArchiveDirectory, None)
self.assertRaises(errors.ParameterError, jstore.GetArchiveDirectory, "foo")
class TestParseJobId(testutils.GanetiTestCase):
def test(self):
self.assertEqual(jstore.ParseJobId(29981), 29981)
self.assertEqual(jstore.ParseJobId("12918"), 12918)
def testErrors(self):
self.assertRaises(errors.ParameterError, jstore.ParseJobId, "")
self.assertRaises(errors.ParameterError, jstore.ParseJobId, "MXXI")
self.assertRaises(errors.ParameterError, jstore.ParseJobId, [])
if __name__ == "__main__":
testutils.GanetiTestProgram()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment