class TestNuleculeXpathing(unittest.TestCase): # Create a temporary directory for our setup as well as load the required NuleculeComponent def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix = "atomicapp-test", dir = "/tmp") self.artifact_path = os.path.dirname(__file__) + '/artifact_xpath_test/xpath.json' self.artifact_content = open(self.artifact_path, 'r').read(); self.test = NuleculeComponent(name = None, basepath = self.tmpdir, params = None) def tearDown(self): pass # Let's check to see that xpathing is actually working. Fake the params get call @mock.patch("atomicapp.nulecule.base.NuleculeComponent.grab_artifact_params", mock_params_get_call) def test_xpathing_parse(self): self.test.apply_pointers(content=self.artifact_content, params={"image": ["/spec/containers/0/image"]}) # Fail if we're unable to replace the /spec/containers/1/image pointer @mock.patch("atomicapp.nulecule.base.NuleculeComponent.grab_artifact_params", mock_params_get_call) def test_xpathing_not_found(self): with pytest.raises(NuleculeException): self.test.apply_pointers(content=self.artifact_content, params={"image": ["/spec/containers/1/image"]}) # Test using the artifact path def test_artifact_path(self): self.test.artifacts = {"docker": [{"file://artifacts/docker/hello-apache-pod_run"}], "kubernetes": [{"file://artifacts/kubernetes/hello-apache-pod.json"}]} self.test.get_artifact_paths_for_provider("kubernetes") # Test the artifact with the "resource: " pointer def test_artifact_path_with_resource(self): self.test.artifacts = {"docker": [{"resource":"file://artifacts/docker/hello-apache-pod_run"}], "kubernetes": [{"resource":"file://artifacts/kubernetes/hello-apache-pod.json"}]} self.test.get_artifact_paths_for_provider("kubernetes") # Test combination of using "resource" and not def test_artifact_path_with_resource_and_old(self): self.test.artifacts = {"docker": [{"resource":"file://artifacts/docker/hello-apache-pod_run"}], "kubernetes": [{"file://artifacts/kubernetes/hello-apache-pod.json"}]} self.test.get_artifact_paths_for_provider("kubernetes")