Пример #1
0
 def test_workload_add_pod_to_manifest(self):
     self.mock_pod.manifest = {"overwrite": "original", "pod-key": "as-is"}
     self.mock_work.pod = self.mock_pod
     self.mock_work.spec = {"overwrite": "replaced"}
     Workload._add_pod_to_manifest(self.mock_work, "Pod")
     self.assertNotIn("template", self.mock_work.spec)
     self.assertIn("replaced", self.mock_work.manifest.values())
     self.assertIn("pod-key", self.mock_work.manifest)
Пример #2
0
class TestWorkload(unittest.TestCase):
    """ UnitTests for Workload Class """

    def setUp(self):
        self.mock_work = Mock(version="", manifest={}, labels={})
        self.mock_work.spec = {}
        self.mock_pod = Mock(manifest={}, labels={"keep_this_label": "x"})
        self.mock_pod.spec = {}

    def test_workload_default_kind_set(self):
        work = Workload("app", "name", {})
        self.assertEqual(work.manifest["kind"], "Deployment")
        work = Workload("app", "name", {"kind": "StatefulSet"})
        self.assertEqual(work.manifest["kind"], "StatefulSet")

    def test_workload_add_pod_to_manifest(self):
        self.mock_pod.manifest = {"overwrite": "original", "pod-key": "as-is"}
        self.mock_work.pod = self.mock_pod
        self.mock_work.spec = {"overwrite": "replaced"}
        Workload._add_pod_to_manifest(self.mock_work, "Pod")
        self.assertNotIn("template", self.mock_work.spec)
        self.assertIn("replaced", self.mock_work.manifest.values())
        self.assertIn("pod-key", self.mock_work.manifest)

    def test_workload_add_workload_to_manifest(self):
        self.mock_pod.manifest = {
            "spec": {"still": "here", "present": "original"}
        }
        self.mock_pod.spec = self.mock_pod.manifest["spec"]
        self.work = Workload("app", "name", {})
        self.work.spec = {
            "template": {"spec": {"present": "replaced", "new": "new"}}
        }
        self.work.pod = self.mock_pod
        self.work._add_pod_to_manifest("StatefulSet")
        self.assertEqual(
            ["here", "replaced", "new"],
            list(self.work.spec["template"]["spec"].values()),
        )
        self.assertIn("here", self.work.spec["template"]["spec"].values())

    def test_workload_add_selector_to_manifest(self):
        self.mock_work.pod = self.mock_pod
        Workload._add_pod_to_manifest(self.mock_work, "Deployment")
        self.assertIn(
            "keep_this_label", self.mock_work.spec["selector"]["matchLabels"]
        )

    def test_workload_add_job_to_manifest(self):
        self.mock_work.pod = self.mock_pod
        Workload._add_pod_to_manifest(self.mock_work, "Job")
        self.assertNotIn("selector", self.mock_work.spec)

    def test_workload_set_version_label(self):
        self.mock_pod.version = "v123"
        self.mock_work.pod = self.mock_pod
        Workload._set_version_label(self.mock_work)
        self.assertEqual(self.mock_work.labels[VER_LABEL], "v123")
Пример #3
0
 def test_workload_add_workload_to_manifest(self):
     self.mock_pod.manifest = {
         "spec": {"still": "here", "present": "original"}
     }
     self.mock_pod.spec = self.mock_pod.manifest["spec"]
     self.work = Workload("app", "name", {})
     self.work.spec = {
         "template": {"spec": {"present": "replaced", "new": "new"}}
     }
     self.work.pod = self.mock_pod
     self.work._add_pod_to_manifest("StatefulSet")
     self.assertEqual(
         ["here", "replaced", "new"],
         list(self.work.spec["template"]["spec"].values()),
     )
     self.assertIn("here", self.work.spec["template"]["spec"].values())
Пример #4
0
 def test_workload_set_version_label(self):
     self.mock_pod.version = "v123"
     self.mock_work.pod = self.mock_pod
     Workload._set_version_label(self.mock_work)
     self.assertEqual(self.mock_work.labels[VER_LABEL], "v123")
Пример #5
0
 def test_workload_add_job_to_manifest(self):
     self.mock_work.pod = self.mock_pod
     Workload._add_pod_to_manifest(self.mock_work, "Job")
     self.assertNotIn("selector", self.mock_work.spec)
Пример #6
0
 def test_workload_add_selector_to_manifest(self):
     self.mock_work.pod = self.mock_pod
     Workload._add_pod_to_manifest(self.mock_work, "Deployment")
     self.assertIn(
         "keep_this_label", self.mock_work.spec["selector"]["matchLabels"]
     )
Пример #7
0
 def test_workload_default_kind_set(self):
     work = Workload("app", "name", {})
     self.assertEqual(work.manifest["kind"], "Deployment")
     work = Workload("app", "name", {"kind": "StatefulSet"})
     self.assertEqual(work.manifest["kind"], "StatefulSet")