def parameters_are_passed_to_test_command_as_environment_variables(operations): source_files = [ plain_file("whack/whack.json", json.dumps({"test": '[ "$VERSION" = "1" ]'})), plain_file("zero", "0"), ] with create_temporary_dir(source_files) as package_source_dir: test_result = operations.test(package_source_dir, params={"version": "1"}) assert_equal(True, test_result.passed)
def test_command_is_run_in_root_of_source_dir(operations): source_files = [ plain_file( "whack/whack.json", json.dumps({"test": "exit `cat zero || echo 1`", "sourcePaths": ["whack", "zero"]}) ), plain_file("zero", "0"), ] with create_temporary_dir(source_files) as package_source_dir: test_result = operations.test(package_source_dir) assert_equal(True, test_result.passed)
def run_script_in_installation_mounts_whack_root_before_running_command(): deployed_package = _deploy_package( [plain_file("message", "Hello there"), sh_script_description("bin/hello", "cat {0}/message".format(WHACK_ROOT))] ) with deployed_package: command = [deployed_package.path("run"), deployed_package.path("bin/hello")] _assert_output(command, b"Hello there")
def _package_source(build_script, description): files = [ plain_file("whack/whack.json", json.dumps(description)), sh_script_description("whack/build", build_script), ] with create_temporary_dir(files) as package_source_dir: yield PackageSource.local(package_source_dir)
def writing_package_source_includes_directories_specified_in_description(): with create_temporary_dir() as package_source_dir: whack_description = { "sourcePaths": ["names"] } write_files(package_source_dir, [ plain_file("whack/whack.json", json.dumps(whack_description)), plain_file("names/bob", "Bob"), ]) with _fetch_source(package_source_dir) as package_source: with create_temporary_dir() as target_dir: package_source.write_to(target_dir) assert_equal( "Bob", read_file(os.path.join(target_dir, "names/bob")) )
def placing_executables_under_dot_sbin_creates_directly_executable_files_under_sbin(): deployed_package = _deploy_package( [ plain_file("message", "Hello there"), sh_script_description(".sbin/hello", "cat {0}/message".format(WHACK_ROOT)), ] ) with deployed_package: command = [deployed_package.path("sbin/hello")] _assert_output(command, b"Hello there")
def relative_symlinks_in_dot_bin_are_created_in_bin(): deployed_package = _deploy_package( [ plain_file("message", "Hello there"), sh_script_description("sub/bin/hello", "cat {0}/message".format(WHACK_ROOT)), symlink(".bin", "sub/bin"), ] ) with deployed_package: command = [deployed_package.path("bin/hello")] _assert_output(command, b"Hello there")
def directory_can_be_deployed_in_place(ops): package_files = [ plain_file("message", "Hello there"), sh_script_description(".bin/hello", "cat {0}/message".format(WHACK_ROOT)), ] with create_temporary_dir(package_files) as package_dir: ops.deploy(package_dir) output = _check_output([os.path.join(package_dir, "bin/hello")]) assert_equal(b"Hello there", output) assert _is_deployed(package_dir)
def error_is_raised_if_build_script_is_missing(): files = [ plain_file("whack/whack.json", json.dumps({})), ] with create_temporary_dir(files) as package_source_dir: package_source = PackageSource.local(package_source_dir) request = create_package_request(package_source, {}) with create_temporary_dir() as target_dir: assert_raises( FileNotFoundError, ("whack/build script not found in package source {0}".format(package_source_dir), ), lambda: build(request, target_dir), )
def whack_root_is_remounted_if_in_different_whack_root(): first_deployed_package = _deploy_package( [ plain_file("message", "Hello there"), sh_script_description(".bin/hello", "cat {0}/message".format(WHACK_ROOT)), ] ) with first_deployed_package: hello_path = first_deployed_package.path("bin/hello") second_deployed_package = _deploy_package([sh_script_description(".bin/hello2", "{0}".format(hello_path))]) with second_deployed_package: _add_echo_to_run_command(first_deployed_package) _add_echo_to_run_command(second_deployed_package) command = [second_deployed_package.path("bin/hello2")] _assert_output(command, b"Run!\nRun!\nHello there")
def writing_source_raises_error_if_file_is_missing(): with create_temporary_dir() as package_source_dir: whack_description = { "sourcePaths": ["name"] } write_files(package_source_dir, [ plain_file("whack/whack.json", json.dumps(whack_description)), ]) with _fetch_source(package_source_dir) as package_source: with create_temporary_dir() as target_dir: assert_raises( FileNotFoundError, lambda: package_source.write_to(target_dir) )
def non_executable_files_under_dot_bin_are_not_created_in_bin(): deployed_package = _deploy_package([plain_file(".bin/message", "Hello there")]) with deployed_package: assert not os.path.exists(deployed_package.path("bin/message"))
def whack_test_passes_if_test_command_has_zero_return_code(operations): source_files = [plain_file("whack/whack.json", json.dumps({"test": "true"}))] with create_temporary_dir(source_files) as package_source_dir: test_result = operations.test(package_source_dir) assert_equal(True, test_result.passed)
def whack_test_fails_if_test_is_not_set_in_whack_json(operations): source_files = [plain_file("whack/whack.json", json.dumps({}))] with create_temporary_dir(source_files) as package_source_dir: test_result = operations.test(package_source_dir) assert_equal(False, test_result.passed)
def _source_package_with_description(description): with create_temporary_dir() as package_source_dir: write_files(package_source_dir, [ plain_file("whack/whack.json", json.dumps(description)), ]) yield PackageSource.local(package_source_dir)
def _create_temporary_package_source_dir(): package_source_files = [plain_file("whack/name", "Bob")] with create_temporary_dir(package_source_files) as package_source_dir: yield package_source_dir