Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
refactor(test-suite): make primitives that are easier to adapt
Lars Wirzenius committed 2 years ago
commit e1f1e94b9245a8e580dadc64f7bafb610800ed33
parent fbd9cc9
1 file changed +69 -26
modified test-suite
@@ -20,27 +20,6 @@ class Suite:
        self.config = Config(tmp)
        self.config.write()

-
    def _test_case(self, repo_name, shell):
-
        git = Git(os.path.join(tmp, repo_name))
-
        git.init()
-
        git.write("README.md", "README")
-
        native = NativeYaml(shell)
-
        debug(f"native.yaml: {native.yaml()}")
-
        git.write(".radicle/native.yaml", native.yaml())
-
        git.commit("first commit")
-
        commit = git.head()
-
        self.rad.init(git)
-
        rid = self.rad.rid(git)
-
        trigger = Trigger(rid, commit)
-
        return self._run_test_case(trigger)
-

-
    def _run_test_case(self, trigger):
-
        ci = NativeCI(self.rad, self.config)
-
        exit, resps = ci.run(trigger)
-
        debug(f"exit: {exit}")
-
        debug(f"responses: {resps}")
-
        return exit, resps
-

    def assert_triggered(self, msg):
        assert msg["response"] == "triggered"

@@ -77,6 +56,36 @@ class Suite:
            chosen = set(methods)
        return chosen

+
    def _setup(self, repo_name, shell):
+
        git = Git(os.path.join(self.tmp, repo_name))
+
        git.init()
+
        git.write("README.md", "README")
+
        native = NativeYaml(shell)
+
        debug(f"native.yaml: {native.yaml()}")
+
        git.write(".radicle/native.yaml", native.yaml())
+
        git.commit("first commit")
+

+
        commit = git.head()
+
        self.rad.init(git)
+
        rid = self.rad.rid(git)
+

+
        return rid, commit
+

+
    def _ci(self):
+
        return NativeCI(self.rad, self.config)
+

+
    def _run_ci(self, ci, rid, commit):
+
        trigger = Trigger(rid, commit)
+
        exit, resps = ci.run(trigger)
+
        debug(f"exit: {exit}")
+
        debug(f"responses: {resps}")
+
        return exit, resps
+

+
    def _test_case(self, repo_name, shell):
+
        rid, commit = self._setup(repo_name, shell)
+
        ci = self._ci()
+
        return self._run_ci(ci, rid, commit)
+

    def test_happy_path(self):
        exit, resps = self._test_case("happy-path", "echo hello, world")
        assert exit == 0
@@ -113,11 +122,11 @@ class Suite:
        self.assert_error(resps[1])

    def test_repository_does_not_exist(self):
-
        trigger = Trigger(
-
            "rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE",
-
            "8d947e182b096ec009e1c9eda9e6a67f5eef83d9",
-
        )
-
        exit, resps = self._run_test_case(trigger)
+
        rid = "rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE"
+
        commit = "8d947e182b096ec009e1c9eda9e6a67f5eef83d9"
+

+
        ci = self._ci()
+
        exit, resps = self._run_ci(ci, rid, commit)

        assert exit != 0
        assert len(resps) == 2
@@ -144,6 +153,40 @@ class Suite:
        # not being a string


+
class TestCase:
+
    def __init__(self, tmp, name):
+
        self._tmp = tmp
+
        self._name = name
+

+
    def shell(self, shell):
+
        self._shell = shell
+

+
    def setup(self, shell):
+
        git = Git(os.path.join(self._tmp, self._name))
+
        git.init()
+
        git.write("README.md", "README")
+
        native = NativeYaml(shell)
+
        debug(f"native.yaml: {native.yaml()}")
+
        git.write(".radicle/native.yaml", native.yaml())
+
        git.commit("first commit")
+

+
        commit = git.head()
+
        self.rad.init(git)
+
        rid = self.rad.rid(git)
+

+
        return rid, commit
+

+
    def create_ci(self, rad, config):
+
        return NativeCI(rad, config)
+

+
    def run_ci(self, ci, rid, commit):
+
        trigger = Trigger(rid, commit)
+
        exit, resps = ci.run(trigger)
+
        debug(f"exit: {exit}")
+
        debug(f"responses: {resps}")
+
        return exit, resps
+

+

class Git:
    def __init__(self, path):
        self.path = path