def test_artifact_paths_for_provider( self, mock_get_artifact_paths_for_path): provider_key = 'some-provider' expected_artifact_paths = [ 'some/path/relative/path/to/artifact1', '/abs/path/to/artifact2', 'some/path/x/artifact3' ] mock_get_artifact_paths_for_path.side_effect = lambda path: [path] nc = NuleculeComponent(name='some-app', basepath='some/path') nc.artifacts = { provider_key: [ 'file://relative/path/to/artifact1', 'file:///abs/path/to/artifact2', { 'inherit': ['x-provider'] } ], 'x-provider': [ 'file://x/artifact3' ] } self.assertEqual(nc.get_artifact_paths_for_provider(provider_key), expected_artifact_paths)
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")