def test_run_s3_validations_binary_access_denied(
            self, storage_service_mock: Mock) -> None:
        expected_report = ValidationReport(
            validation_result=ValidationResult.FAILED,
            validator_name=BINARY_FILE_VALIDATOR_NAME,
            message=
            f"You don't have permission to access some private computation software (Repo path: {DEFAULT_BINARY_REPOSITORY}, software version: {DEFAULT_BINARY_VERSION}). Please contact your representative at Meta",
            details={
                f"{DEFAULT_BINARY_REPOSITORY}package/3/latest/binary":
                "An error occurred (403) when calling the HeadObject operation: Forbidden"
            },
        )
        storage_service_mock.__init__(return_value=storage_service_mock)
        storage_service_mock.file_exists.side_effect = [
            True,
            True,
            PcpError(
                Exception(
                    "An error occurred (403) when calling the HeadObject operation: Forbidden"
                )),
        ]
        validator = BinaryFileValidator(TEST_REGION, TEST_BINARY_INFOS)
        report = validator.validate()

        self.assertEqual(report, expected_report)
        self.assertEqual(storage_service_mock.file_exists.call_count,
                         len(TEST_BINARY_INFOS))
    def test_run_local_validations_success(self, storage_service_mock: Mock,
                                           mock_file_exists: Mock) -> None:
        expected_report = ValidationReport(
            validation_result=ValidationResult.SUCCESS,
            validator_name=BINARY_FILE_VALIDATOR_NAME,
            message=
            f"Completed binary accessibility validation successfully (Repo path: LOCAL, binary folder: {DEFAULT_EXE_FOLDER}).",
        )
        mock_file_exists.return_value = True

        validator = BinaryFileValidator(TEST_REGION, TEST_BINARY_INFOS)
        report = validator.validate()

        self.assertEqual(report, expected_report)
        self.assertEqual(mock_file_exists.call_count, len(TEST_BINARY_INFOS))
    def test_run_local_validations_binary_not_exist(
            self, storage_service_mock: Mock, mock_file_exists: Mock) -> None:
        expected_report = ValidationReport(
            validation_result=ValidationResult.FAILED,
            validator_name=BINARY_FILE_VALIDATOR_NAME,
            message=
            f"You don't have permission to access some private computation software (Repo path: LOCAL, binary folder: {DEFAULT_EXE_FOLDER}). Please contact your representative at Meta",
            details={f"{DEFAULT_EXE_FOLDER}1": "binary does not exist"},
        )
        mock_file_exists.side_effect = [False, True, True]

        validator = BinaryFileValidator(TEST_REGION, TEST_BINARY_INFOS)
        report = validator.validate()

        self.assertEqual(report, expected_report)
        self.assertEqual(mock_file_exists.call_count, len(TEST_BINARY_INFOS))
    def test_run_s3_validations_unexpected_error(
            self, storage_service_mock: Mock) -> None:
        expected_report = ValidationReport(
            validation_result=ValidationResult.SUCCESS,
            validator_name=BINARY_FILE_VALIDATOR_NAME,
            message=
            f"WARNING: {BINARY_FILE_VALIDATOR_NAME} threw an unexpected error: An internal error occurred (500)",
        )
        storage_service_mock.__init__(return_value=storage_service_mock)
        storage_service_mock.file_exists.side_effect = PcpError(
            Exception("An internal error occurred (500)"))
        validator = BinaryFileValidator(TEST_REGION, TEST_BINARY_INFOS)
        report = validator.validate()

        self.assertEqual(report, expected_report)
        self.assertEqual(storage_service_mock.file_exists.call_count, 1)
    def test_run_s3_validations_binary_not_exist(
            self, storage_service_mock: Mock) -> None:
        expected_report = ValidationReport(
            validation_result=ValidationResult.FAILED,
            validator_name=BINARY_FILE_VALIDATOR_NAME,
            message=
            f"You don't have permission to access some private computation software (Repo path: {DEFAULT_BINARY_REPOSITORY}, software version: {DEFAULT_BINARY_VERSION}). Please contact your representative at Meta",
            details={
                f"{DEFAULT_BINARY_REPOSITORY}package/1/latest/1":
                "binary does not exist"
            },
        )
        storage_service_mock.__init__(return_value=storage_service_mock)
        storage_service_mock.file_exists.side_effect = [False, True, True]

        validator = BinaryFileValidator(TEST_REGION, TEST_BINARY_INFOS)
        report = validator.validate()

        self.assertEqual(report, expected_report)
        self.assertEqual(storage_service_mock.file_exists.call_count,
                         len(TEST_BINARY_INFOS))
    def test_run_s3_validations_success(self,
                                        storage_service_mock: Mock) -> None:
        expected_report = ValidationReport(
            validation_result=ValidationResult.SUCCESS,
            validator_name=BINARY_FILE_VALIDATOR_NAME,
            message=
            f"Completed binary accessibility validation successfully (Repo path: {DEFAULT_BINARY_REPOSITORY}, software version: {DEFAULT_BINARY_VERSION}).",
        )
        storage_service_mock.__init__(return_value=storage_service_mock)
        storage_service_mock.file_exists.return_value = True

        validator = BinaryFileValidator(TEST_REGION, TEST_BINARY_INFOS)
        report = validator.validate()

        self.assertEqual(report, expected_report)
        self.assertEqual(storage_service_mock.file_exists.call_count,
                         len(TEST_BINARY_INFOS))
        storage_service_mock.file_exists.assert_has_calls([
            call(f"{DEFAULT_BINARY_REPOSITORY}package/1/latest/1"),
            call(f"{DEFAULT_BINARY_REPOSITORY}package/2/latest/2"),
            call(f"{DEFAULT_BINARY_REPOSITORY}package/3/latest/binary"),
        ])