Index: infra/libs/git2/test/config_ref_test.py |
diff --git a/infra/services/gnumbd/test/config_test.py b/infra/libs/git2/test/config_ref_test.py |
similarity index 60% |
rename from infra/services/gnumbd/test/config_test.py |
rename to infra/libs/git2/test/config_ref_test.py |
index 7538c95939bf3f6d945f483ee5a3f6f7966fbe1f..1ef6d5fc93f3bfde1ddf68bb4eaa5c1853f622cd 100644 |
--- a/infra/services/gnumbd/test/config_test.py |
+++ b/infra/libs/git2/test/config_ref_test.py |
@@ -2,16 +2,34 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-from infra.services.gnumbd.support import config_ref, git |
-from infra.services.gnumbd.test import git_test |
+from infra.libs.git2 import config_ref |
-class TestConfigRef(git_test.TestBasis): |
+from infra.libs.git2.test import git2_test |
+ |
+META_REF = 'refs/metaconfig' |
+ |
+class ExampleRef(config_ref.ConfigRef): |
+ CONVERT = { |
+ 'interval': lambda self, val: float(val), |
+ 'pending_tag_prefix': lambda self, val: str(val), |
+ 'pending_ref_prefix': lambda self, val: str(val), |
+ 'enabled_refglobs': lambda self, val: map(str, list(val)), |
+ } |
+ DEFAULTS = { |
+ 'interval': 5.0, |
+ 'pending_tag_prefix': 'refs/pending-tags', |
+ 'pending_ref_prefix': 'refs/pending', |
+ 'enabled_refglobs': [], |
+ } |
+ REF = META_REF |
+ |
+ |
+class TestConfigRef(git2_test.TestBasis): |
def writeConfig(self, config_data): |
- ref = 'refs/metaconfig' |
def inner(): |
g = self.repo.git |
- if g('rev-parse', ref).stdout.strip() != ref: |
- g('checkout', ref) |
+ if g('rev-parse', META_REF).stdout.strip() != META_REF: |
+ g('checkout', META_REF) |
else: |
g('checkout', '--orphan', 'config') |
g('rm', '-rf', '.') |
@@ -19,19 +37,19 @@ class TestConfigRef(git_test.TestBasis): |
f.write(config_data) |
g('add', 'config.json') |
self.repo.git_commit('a bad config file') |
- g('update-ref', ref, 'HEAD') |
+ g('update-ref', META_REF, 'HEAD') |
self.repo.run(inner) |
def testNonExist(self): |
r = self.mkRepo() |
- c = config_ref.ConfigRef(git.Ref(r, 'refs/metaconfig')) |
+ c = ExampleRef(r) |
self.assertEqual(c.current, c.DEFAULTS) |
self.assertEqual(c['interval'], c.DEFAULTS['interval']) |
def testExistsBad(self): |
self.writeConfig("not valid config") |
r = self.mkRepo() |
- c = config_ref.ConfigRef(git.Ref(r, 'refs/metaconfig')) |
+ c = ExampleRef(r) |
c.evaluate() |
self.assertEqual(c.current, c.DEFAULTS) |
@@ -43,7 +61,7 @@ class TestConfigRef(git_test.TestBasis): |
def testExistsGood(self): |
self.writeConfig('{"interval": 100}') |
r = self.mkRepo() |
- c = config_ref.ConfigRef(git.Ref(r, 'refs/metaconfig')) |
+ c = ExampleRef(r) |
self.assertAlmostEqual(c['interval'], 100.0) |
self.writeConfig('{"interval": "cat"}') |