def test_fail_does_not_exist(self, caplog, tmp_path): filename = str(tmp_path / "does-not-exist.json") result = parse_manifest(filename) assert result is None assert caplog.record_tuples == [( "scout_apm.core.agent.manager", logging.DEBUG, "Core Agent Manifest does not exist at " + filename, )]
def test_fail_core_agent_binary_not_string(self, caplog, tmp_path): manifest = tmp_path / "manifest.json" manifest.write_text('{"core_agent_binary": 1}') result = parse_manifest(str(manifest)) assert result is None assert len(caplog.record_tuples) == 2 assert caplog.record_tuples[1] == ( "scout_apm.core.agent.manager", logging.DEBUG, "Error parsing Core Agent Manifest", )
def test_success(self, caplog, tmp_path): manifest = tmp_path / "manifest.json" manifest.write_text( '{"core_agent_binary": "bin", "core_agent_version": "1.2.3", ' + '"core_agent_binary_sha256": "abc"}') result = parse_manifest(str(manifest)) assert result.bin_name == "bin" assert result.bin_version == "1.2.3" assert result.sha256 == "abc" logger, level, message = caplog.record_tuples[0] assert logger == "scout_apm.core.agent.manager" assert level == logging.DEBUG assert message.startswith("Core Agent manifest json: ")
def test_fail_other_open_error(self, caplog, tmp_path): filename = str(tmp_path / "does-not-exist.json") if sys.version_info[0] == 2: error = IOError("Woops", errno.EACCES) else: error = OSError(errno.EACCES) mock_open = mock.patch( "scout_apm.core.agent.manager.open", create=True, side_effect=error, ) with mock_open: result = parse_manifest(filename) assert result is None assert caplog.record_tuples == [( "scout_apm.core.agent.manager", logging.DEBUG, "Error opening Core Agent Manifest at " + filename, )]