From 3318ca8da2e8aae213bfc352132fbde5c4c4f91a Mon Sep 17 00:00:00 2001 From: realaravinth Date: Mon, 27 Jun 2022 04:53:52 +0530 Subject: [PATCH] feat: infrastructure tests: check if commits are pushed to remote --- infrastructure/tests.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/infrastructure/tests.py b/infrastructure/tests.py index c8f5ac4..d549ffe 100644 --- a/infrastructure/tests.py +++ b/infrastructure/tests.py @@ -17,6 +17,7 @@ import shutil from django.test import TestCase, Client, override_settings from django.conf import settings +from git import Repo from dash.models import Instance from .utils import Infra @@ -80,6 +81,7 @@ class InfraUtilTest(TestCase): def test_add_vm(self): infra = Infra() c = Client() + conf = settings.HOSTEA["INFRA"]["HOSTEA_REPO"] login_util(self, c, "accounts.home") subdomain = "add_vm" @@ -89,7 +91,23 @@ class InfraUtilTest(TestCase): t=self, c=c, instance_name=subdomain, config=self.instance_config[0] ) + before_add = infra.repo.head.commit.hexsha instance = Instance.objects.get(name=subdomain) woodpecker_agent_secret = infra.add_vm(instance=instance) + after_add = infra.repo.head.commit.hexsha + self.assertEqual(before_add is not after_add, True) + c = custom_config(test_name="test_add_vm--get-head") + path = c["INFRA"]["HOSTEA_REPO"]["PATH"] + repo = Repo.clone_from( + conf["REMOTE"], path, env={"GIT_SSH_COMMAND": infra.ssh_cmd} + ) + self.assertEqual(repo.head.commit.hexsha == after_add, True) + + before_rm = infra.repo.head.commit.hexsha infra.remove_vm(instance=instance) + after_rm = infra.repo.head.commit.hexsha + self.assertEqual(before_add is not after_add, True) + + repo.git.pull() + self.assertEqual(repo.head.commit.hexsha == after_rm, True)