|
| 1 | +from unittest import TestCase |
| 2 | + |
| 3 | +from ravendb_embedded.options import ServerOptions |
| 4 | +from ravendb_embedded.runtime_framework_version_matcher import RuntimeFrameworkVersionMatcher, RuntimeFrameworkVersion |
| 5 | + |
| 6 | + |
| 7 | +class TestRuntimeFrameworkVersionMatcher(TestCase): |
| 8 | + def test_match_1(self): |
| 9 | + options = ServerOptions() |
| 10 | + default_framework_version = ServerOptions.INSTANCE().framework_version |
| 11 | + |
| 12 | + self.assertIn(RuntimeFrameworkVersionMatcher.GREATER_OR_EQUAL, default_framework_version) |
| 13 | + |
| 14 | + options.framework_version = None |
| 15 | + self.assertIsNone(RuntimeFrameworkVersionMatcher.match(options)) |
| 16 | + |
| 17 | + options = ServerOptions() |
| 18 | + framework_version = RuntimeFrameworkVersion(options.framework_version) |
| 19 | + framework_version.patch = None |
| 20 | + |
| 21 | + options.framework_version = framework_version.__str__() |
| 22 | + match = RuntimeFrameworkVersionMatcher.match(options) |
| 23 | + self.assertIsNotNone(match) |
| 24 | + |
| 25 | + match_framework_version = RuntimeFrameworkVersion(match) |
| 26 | + self.assertIsNotNone(match_framework_version.major) |
| 27 | + self.assertIsNotNone(match_framework_version.minor) |
| 28 | + self.assertIsNotNone(match_framework_version.patch) |
| 29 | + |
| 30 | + self.assertTrue(framework_version.match(match_framework_version)) |
| 31 | + |
| 32 | + def test_match_2(self): |
| 33 | + runtimes = self.get_runtimes() |
| 34 | + |
| 35 | + runtime = RuntimeFrameworkVersion("3.1.1") |
| 36 | + self.assertEqual(RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes), "3.1.1") |
| 37 | + |
| 38 | + runtime = RuntimeFrameworkVersion("2.1.11") |
| 39 | + self.assertEqual(RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes), "2.1.11") |
| 40 | + |
| 41 | + runtime = RuntimeFrameworkVersion("3.1.x") |
| 42 | + self.assertEqual(RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes), "3.1.3") |
| 43 | + |
| 44 | + runtime = RuntimeFrameworkVersion("3.x") |
| 45 | + self.assertEqual(RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes), "3.2.3") |
| 46 | + |
| 47 | + runtime = RuntimeFrameworkVersion("3.x.x") |
| 48 | + self.assertEqual(RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes), "3.2.3") |
| 49 | + |
| 50 | + runtime = RuntimeFrameworkVersion("5.0.x") |
| 51 | + self.assertEqual(RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes), "5.0.4") |
| 52 | + |
| 53 | + runtime = RuntimeFrameworkVersion("x") |
| 54 | + self.assertEqual(RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes), "5.0.4") |
| 55 | + |
| 56 | + runtime = RuntimeFrameworkVersion("5.0.x-rc.2.20475.17") |
| 57 | + self.assertEqual(RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes), "5.0.0-rc.2.20475.17") |
| 58 | + |
| 59 | + runtime = RuntimeFrameworkVersion("6.x") |
| 60 | + |
| 61 | + with self.assertRaises(RuntimeError): |
| 62 | + RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes) |
| 63 | + |
| 64 | + def test_match_3(self): |
| 65 | + runtime = RuntimeFrameworkVersion("3.1.0-rc") |
| 66 | + self.assertEqual(str(runtime), "3.1.0-rc") |
| 67 | + |
| 68 | + runtime = RuntimeFrameworkVersion("5.0.0-rc.2.20475.17") |
| 69 | + self.assertEqual(str(runtime), "5.0.0-rc.2.20475.17") |
| 70 | + |
| 71 | + def test_match_4(self): |
| 72 | + runtimes = self.get_runtimes() |
| 73 | + |
| 74 | + runtime = RuntimeFrameworkVersion("3.1.1+") |
| 75 | + self.assertEqual(str(runtime), "3.1.1+") |
| 76 | + self.assertEqual(RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes), "3.1.3") |
| 77 | + |
| 78 | + runtime = RuntimeFrameworkVersion("3.1.4+") |
| 79 | + self.assertEqual(str(runtime), "3.1.4+") |
| 80 | + |
| 81 | + with self.assertRaises(RuntimeError) as context: |
| 82 | + RuntimeFrameworkVersionMatcher.match_runtime(runtime, runtimes) |
| 83 | + self.assertIn("Could not find a matching runtime for '3.1.4+'. Available runtimes:", str(context.exception)) |
| 84 | + |
| 85 | + with self.assertRaises(RuntimeError) as context: |
| 86 | + RuntimeFrameworkVersion("6.0.0+-preview.6.21352.12") |
| 87 | + self.assertIn( |
| 88 | + "Cannot set 'patch' with value '0+' because '+' is not allowed when suffix ('preview.6.21352.12') is set", |
| 89 | + str(context.exception), |
| 90 | + ) |
| 91 | + |
| 92 | + with self.assertRaises(RuntimeError) as context: |
| 93 | + RuntimeFrameworkVersion("6+") |
| 94 | + self.assertIn("Cannot set 'major' with value '6+' because '+' is not allowed.", str(context.exception)) |
| 95 | + |
| 96 | + with self.assertRaises(RuntimeError) as context: |
| 97 | + RuntimeFrameworkVersion("3.1+") |
| 98 | + self.assertIn("Cannot set 'minor' with value '1+' because '+' is not allowed.", str(context.exception)) |
| 99 | + |
| 100 | + def get_runtimes(self): |
| 101 | + result = [ |
| 102 | + RuntimeFrameworkVersion("2.1.3"), |
| 103 | + RuntimeFrameworkVersion("2.1.4"), |
| 104 | + RuntimeFrameworkVersion("2.1.11"), |
| 105 | + RuntimeFrameworkVersion("2.2.0"), |
| 106 | + RuntimeFrameworkVersion("2.2.1"), |
| 107 | + RuntimeFrameworkVersion("3.1.0"), |
| 108 | + RuntimeFrameworkVersion("3.1.1"), |
| 109 | + RuntimeFrameworkVersion("3.1.2"), |
| 110 | + RuntimeFrameworkVersion("3.1.3"), |
| 111 | + RuntimeFrameworkVersion("3.2.3"), |
| 112 | + RuntimeFrameworkVersion("5.0.0-rc.2.20475.17"), |
| 113 | + RuntimeFrameworkVersion("5.0.3"), |
| 114 | + RuntimeFrameworkVersion("5.0.4"), |
| 115 | + RuntimeFrameworkVersion("6.0.0-preview.6.21352.12"), |
| 116 | + ] |
| 117 | + |
| 118 | + return result |
0 commit comments