test_that("extract_version extracts correct version", {
test_that("extract_version returns NULL for invalid paths", {
test_that("extract_version handles edge cases", {
test_that("fetch_bioconductor_releases returns valid HTML from mock input", {
content = charToRaw("<html><head><title>Mock Page</title></head><body><h1>Bioconductor Releases</h1></body></html>")
# Use stub to replace curl_fetch_memory with the mock function
test_that("fetch_bioconductor_releases returns FALSE on 404", {
# Mock function to simulate a 404 response
test_that("parse_bioconductor_releases correctly extracts release data", {
# Define mock HTML with a table structure
<th>Release</th> <th>Date</th> <th>Software Packages</th> <th>R Version</th>
list(release = "3.15", date = "2022-04-27", software_packages = "1945", r_version = "R 4.2")
# Check if extracted data matches expected output
test_that("fetch_bioconductor_package_info returns main + archive versions", {
# Mock curl::curl_fetch_memory to return raw HTML content
# This mock returns the main package HTML (called early via curl)
return(list(status_code = 200, content = charToRaw(html)))
if (is.list(x) && !is.null(x$content)) {
message("✅ read_html called with RAW response")
} else if (is.character(x) && grepl("^<html>", x)) {
} else if (is.character(x) && x == "https://bioconductor.org/packages/3.20/bioc/html/limma.html") {
} else if (is.character(x) && x == "https://bioconductor.org/packages/3.20/bioc/src/contrib/Archive/limma/") {
test_that("fetch_bioconductor_package_info returns only main version when no archive exists", {
return(list(status_code = 404, content = raw(0)))
test_that("fetch_bioconductor_package_info returns only archive versions when no main version exists", {
return(list(status_code = 200, content = charToRaw(archive_html)))
test_that("fetch_bioconductor_package_info returns FALSE when package is not found", {
mock_fetch_bioconductor_package_info <- function(bioconductor_version, package_name) {
# Simulate different Bioconductor versions and package availability
source_package = paste0("https://bioconductor.org/packages/", bioconductor_version, "/bioc/src/contrib/DESeq2_1.38.0.tar.gz"),
source_package = paste0("https://bioconductor.org/packages/", bioconductor_version, "/bioc/src/contrib/edgeR_3.40.2.tar.gz"),
return(NULL)  # Simulate non-existing package
test_that("get_bioconductor_package_url returns correct URL for DESeq2", {
result <- get_bioconductor_package_url("DESeq2", release_data = release_data)
test_that("get_bioconductor_package_url returns correct URL for older package version", {
# Call function for an older version of edgeR
result <- get_bioconductor_package_url("edgeR", package_version = "3.40.2", release_data = release_data)
test_that("get_bioconductor_package_url returns NULL for non-existing package", {
result <- get_bioconductor_package_url("NonExistentPackage", release_data = release_data)
test_that("get_bioconductor_package_url handles errors gracefully", {
# Define a mock function that simulates an error
mock_fetch_error <- function(bioconductor_version, package_name) {
# Stub the fetch function with the error simulation