Debian Codegraph @

tests/testthat/test-ppm.R

raw
1
2 test_that("we can transform binary URLs into source URLs", {
3 skip_on_cran()
4 skip_on_os("windows")
5
6 url <- "https://packagemanager.rstudio.com/cran/__linux__/centos7/latest"
7
8 actual <- renv_ppm_normalize(url)
9 expected <- "https://packagemanager.rstudio.com/cran/latest"
10 expect_identical(actual, expected)
11
12 })
13
14 test_that("repository URLs are properly transformed for different platforms", {
15 skip_on_cran()
16 skip_on_os("windows")
17
18 renv_scope_envvars(RENV_RSPM_OS = "__linux__", RENV_RSPM_PLATFORM = "bionic")
19 repos <- c(RSPM = "https://cluster.rstudiopm.com/cran/latest")
20 expected <- c(RSPM = "https://cluster.rstudiopm.com/cran/__linux__/bionic/latest")
21 actual <- renv_ppm_transform(repos)
22 expect_identical(expected, actual)
23
24 })
25
26 test_that("a binary-specific URL is transformed before writing a lockfile", {
27 skip_on_cran()
28
29 renv_tests_scope()
30 renv_scope_options(repos = c(RSPM = "https://cluster.rstudiopm.com/cran/__os__/platform/latest"))
31 lockfile <- snapshot(lockfile = NULL)
32 actual <- convert(lockfile$R$Repositories, "character")
33 expected <- c(RSPM = "https://cluster.rstudiopm.com/cran/latest")
34 expect_identical(actual, expected)
35
36 })
37
38 test_that("RSPM bits are preserved when writing lockfile", {
39 skip_on_cran()
40
41 renv_tests_scope()
42 renv_scope_options(repos = c(RSPM = "https://cluster.rstudiopm.com/curated/__linux__/bionic/12"))
43 lockfile <- snapshot(lockfile = NULL)
44 actual <- convert(lockfile$R$Repositories, "character")
45 expected <- c(RSPM = "https://cluster.rstudiopm.com/curated/12")
46 expect_identical(actual, expected)
47
48 })
49
50 test_that("renv correctly detects RHEL < 9 as CentOS for RSPM", {
51 skip_on_cran()
52 skip_on_os("windows")
53
54 release <- heredoc('
55 NAME="Red Hat Enterprise Linux Server"
56 VERSION="7.9 (Maipo)"
57 ID="rhel"
58 ID_LIKE="fedora"
59 VARIANT="Server"
60 VARIANT_ID="server"
61 VERSION_ID="7.9"
62 PRETTY_NAME="Red Hat Enterprise Linux Server 7.9 (Maipo)"
63 ANSI_COLOR="0;31"
64 CPE_NAME="cpe:/o:redhat:enterprise_linux:7.9:GA:server"
65 HOME_URL="https://www.redhat.com/"
66 BUG_REPORT_URL="https://bugzilla.redhat.com/"
67 ')
68
69 file <- renv_scope_tempfile()
70 writeLines(release, con = file)
71
72 platform <- renv_ppm_platform_impl(file = file)
73 expect_equal(platform, "centos7")
74
75 })
76
77 test_that("renv correctly detects RHEL9 for PPM", {
78 skip_on_cran()
79 skip_on_os("windows")
80
81 release <- heredoc('
82 NAME="Red Hat Enterprise Linux"
83 VERSION="9.0 (Plow)"
84 ID="rhel"
85 ID_LIKE="fedora"
86 VERSION_ID="9.0"
87 PLATFORM_ID="platform:el9"
88 PRETTY_NAME="Red Hat Enterprise Linux 9.0 (Plow)"
89 ANSI_COLOR="0;31"
90 LOGO="fedora-logo-icon"
91 CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos"
92 HOME_URL="https://www.redhat.com/"
93 DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/9/"
94 BUG_REPORT_URL="https://bugzilla.redhat.com/"
95
96 REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 9"
97 REDHAT_BUGZILLA_PRODUCT_VERSION=9.0
98 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
99 REDHAT_SUPPORT_PRODUCT_VERSION="9.0"
100 ')
101
102 file <- renv_scope_tempfile()
103 writeLines(release, con = file)
104
105 platform <- renv_ppm_platform_impl(file = file)
106 expect_equal(platform, "rhel9")
107
108 })
109
110 test_that("renv correctly detects Rocky Linux 8 as centos8 for PPM", {
111 skip_on_cran()
112 skip_on_os("windows")
113
114 release <- heredoc('
115 NAME="Rocky Linux"
116 VERSION="8.8 (Green Obsidian)"
117 ID="rocky"
118 ID_LIKE="rhel centos fedora"
119 VERSION_ID="8.8"
120 PLATFORM_ID="platform:el8"
121 PRETTY_NAME="Rocky Linux 8.8 (Green Obsidian)"
122 ANSI_COLOR="0;32"
123 LOGO="fedora-logo-icon"
124 CPE_NAME="cpe:/o:rocky:rocky:8:GA"
125 HOME_URL="https://rockylinux.org/"
126 BUG_REPORT_URL="https://bugs.rockylinux.org/"
127 SUPPORT_END="2029-05-31"
128 ROCKY_SUPPORT_PRODUCT="Rocky-Linux-8"
129 ROCKY_SUPPORT_PRODUCT_VERSION="8.8"
130 REDHAT_SUPPORT_PRODUCT="Rocky Linux"
131 REDHAT_SUPPORT_PRODUCT_VERSION="8.8"
132 ')
133
134 file <- renv_scope_tempfile()
135 writeLines(release, con = file)
136
137 platform <- renv_ppm_platform_impl(file = file)
138 expect_equal(platform, "centos8")
139
140 })
141
142 test_that("renv correctly detects Rocky Linux 9 as rhel9 for PPM", {
143 skip_on_cran()
144 skip_on_os("windows")
145
146 release <- heredoc('
147 NAME="Rocky Linux"
148 VERSION="9.2 (Blue Onyx)"
149 ID="rocky"
150 ID_LIKE="rhel centos fedora"
151 VERSION_ID="9.2"
152 PLATFORM_ID="platform:el9"
153 PRETTY_NAME="Rocky Linux 9.2 (Blue Onyx)"
154 ANSI_COLOR="0;32"
155 LOGO="fedora-logo-icon"
156 CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
157 HOME_URL="https://rockylinux.org/"
158 BUG_REPORT_URL="https://bugs.rockylinux.org/"
159 SUPPORT_END="2032-05-31"
160 ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
161 ROCKY_SUPPORT_PRODUCT_VERSION="9.2"
162 REDHAT_SUPPORT_PRODUCT="Rocky Linux"
163 REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
164 ')
165
166 file <- renv_scope_tempfile()
167 writeLines(release, con = file)
168
169 platform <- renv_ppm_platform_impl(file = file)
170 expect_equal(platform, "rhel9")
171
172 })
173
174 test_that("renv correctly detects AlmaLinux 9 as rhel9 for PPM", {
175 skip_on_cran()
176 skip_on_os("windows")
177
178 release <- heredoc('
179 NAME="AlmaLinux"
180 VERSION="9.2 (Turquoise Kodkod)"
181 ID="almalinux"
182 ID_LIKE="rhel centos fedora"
183 VERSION_ID="9.2"
184 PLATFORM_ID="platform:el9"
185 PRETTY_NAME="AlmaLinux 9.2 (Turquoise Kodkod)"
186 ANSI_COLOR="0;34"
187 LOGO="fedora-logo-icon"
188 CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos"
189 HOME_URL="https://almalinux.org/"
190 DOCUMENTATION_URL="https://wiki.almalinux.org/"
191 BUG_REPORT_URL="https://bugs.almalinux.org/"
192
193 ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9"
194 ALMALINUX_MANTISBT_PROJECT_VERSION="9.2"
195 REDHAT_SUPPORT_PRODUCT="AlmaLinux"
196 REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
197 ')
198
199 file <- renv_scope_tempfile()
200 writeLines(release, con = file)
201
202 platform <- renv_ppm_platform_impl(file = file)
203 expect_equal(platform, "rhel9")
204
205 })
206
207 test_that("renv correctly detects OpenSUSE for PPM", {
208 skip_on_cran()
209 skip_on_os("windows")
210
211 release <- heredoc('
212 NAME="openSUSE Leap"
213 VERSION="15.4"
214 ID="opensuse-leap"
215 ID_LIKE="suse opensuse"
216 VERSION_ID="15.4"
217 PRETTY_NAME="openSUSE Leap 15.4"
218 ANSI_COLOR="0;32"
219 CPE_NAME="cpe:/o:opensuse:leap:15.4"
220 BUG_REPORT_URL="https://bugs.opensuse.org"
221 HOME_URL="https://www.opensuse.org/"
222 DOCUMENTATION_URL="https://en.opensuse.org/Portal:Leap"
223 LOGO="distributor-logo-Leap"
224 ')
225
226 file <- renv_scope_tempfile()
227 writeLines(release, con = file)
228
229 platform <- renv_ppm_platform_impl(file = file)
230 expect_equal(platform, "opensuse154")
231
232 })
233
234 test_that("renv correctly detects SLES as OpenSUSE for PPM", {
235 skip_on_cran()
236 skip_on_os("windows")
237
238 # `docker run -it registry.suse.com/suse/sle15:15.5`
239 release <- heredoc('
240 NAME="SLES"
241 VERSION="15-SP5"
242 VERSION_ID="15.5"
243 PRETTY_NAME="SUSE Linux Enterprise Server 15 SP5"
244 ID="sles"
245 ID_LIKE="suse"
246 ANSI_COLOR="0;32"
247 CPE_NAME="cpe:/o:suse:sles:15:sp5"
248 DOCUMENTATION_URL="https://documentation.suse.com/"
249 ')
250
251 file <- renv_scope_tempfile()
252 writeLines(release, con = file)
253
254 platform <- renv_ppm_platform_impl(file = file)
255 expect_equal(platform, "opensuse155")
256
257 })
258
259 test_that("renv correctly detects Debian for PPM", {
260 skip_on_cran()
261 skip_on_os("windows")
262
263 release <- heredoc('
264 PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
265 NAME="Debian GNU/Linux"
266 VERSION_ID="11"
267 VERSION="11 (bullseye)"
268 VERSION_CODENAME=bullseye
269 ID=debian
270 HOME_URL="https://www.debian.org/"
271 SUPPORT_URL="https://www.debian.org/support"
272 BUG_REPORT_URL="https://bugs.debian.org/"
273 ')
274
275 file <- renv_scope_tempfile()
276 writeLines(release, con = file)
277
278 platform <- renv_ppm_platform_impl(file = file)
279 expect_equal(platform, "bullseye")
280
281 })
282
283 test_that("renv correctly detects Ubuntu for PPM", {
284 skip_on_cran()
285 skip_on_os("windows")
286
287 release <- heredoc('
288 NAME="Ubuntu"
289 VERSION="20.04.6 LTS (Focal Fossa)"
290 ID=ubuntu
291 ID_LIKE=debian
292 PRETTY_NAME="Ubuntu 20.04.6 LTS"
293 VERSION_ID="20.04"
294 HOME_URL="https://www.ubuntu.com/"
295 SUPPORT_URL="https://help.ubuntu.com/"
296 BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
297 PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
298 VERSION_CODENAME=focal
299 UBUNTU_CODENAME=focal
300 ')
301
302 file <- renv_scope_tempfile()
303 writeLines(release, con = file)
304
305 platform <- renv_ppm_platform_impl(file = file)
306 expect_equal(platform, "focal")
307
308 })
309
310 test_that("renv correctly detects Amazon Linux 2 as centos7 for PPM", {
311 skip_on_cran()
312 skip_on_os("windows")
313
314 release <- heredoc('
315 NAME="Amazon Linux"
316 VERSION="2"
317 ID="amzn"
318 ID_LIKE="centos rhel fedora"
319 VERSION_ID="2"
320 PRETTY_NAME="Amazon Linux 2"
321 ANSI_COLOR="0;33"
322 CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
323 HOME_URL="https://amazonlinux.com/"
324 SUPPORT_END="2025-06-30"
325 ')
326
327 file <- renv_scope_tempfile()
328 writeLines(release, con = file)
329
330 platform <- renv_ppm_platform_impl(file = file)
331 expect_equal(platform, "centos7")
332
333 })
334
335 test_that("renv detects no supported PPM platform for Amazon Linux 2023", {
336 skip_on_cran()
337 skip_on_os("windows")
338
339 release <- heredoc('
340 NAME="Amazon Linux"
341 VERSION="2023"
342 ID="amzn"
343 ID_LIKE="fedora"
344 VERSION_ID="2023"
345 PLATFORM_ID="platform:al2023"
346 PRETTY_NAME="Amazon Linux 2023"
347 ANSI_COLOR="0;33"
348 CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
349 HOME_URL="https://aws.amazon.com/linux/"
350 BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
351 SUPPORT_END="2028-03-01"
352 ')
353
354 file <- renv_scope_tempfile()
355 writeLines(release, con = file)
356
357 platform <- renv_ppm_platform_impl(file = file)
358 expect_null(platform)
359
360 })
361
362 test_that("URLs like http://foo/bar aren't queried", {
363 skip_on_cran()
364 skip_on_os("windows")
365
366 # pretend to be Ubuntu
367 renv_scope_envvars(
368 RENV_PPM_OS = "__linux__",
369 RENV_PPM_PLATFORM = "ubuntu"
370 )
371
372 # emit a condition that we can catch on
373 renv_scope_trace(renv:::renv_ppm_status, quote(
374 renv_condition_signal("bail")
375 ))
376
377 # should exit early
378 status <- expect_no_condition(renv_ppm_transform_impl("http://foo/bar"), class = "bail")
379 expect_equal(status, "http://foo/bar")
380
381 # should emit a condition now
382 expect_condition(renv_ppm_transform_impl("http://foo/bar/baz"), class = "bail")
383
384 })
385
386 test_that("renv_ppm_transform() uses source URLs when appropriate", {
387 skip_on_cran()
388 skip_on_os("windows")
389
390 # pretend to be Ubuntu
391 renv_scope_envvars(
392 RENV_PPM_OS = "__linux__",
393 RENV_PPM_PLATFORM = "jammy"
394 )
395
396 binurl <- "https://packagemanager.rstudio.com/cran/__linux__/jammy/latest"
397 srcurl <- "https://packagemanager.rstudio.com/cran/latest"
398
399 # prefer source URLs
400 renv_scope_binding(the, "install_pkg_type", "source")
401 expect_equal(unname(renv_ppm_transform(binurl)), srcurl)
402 expect_equal(unname(renv_ppm_transform(srcurl)), srcurl)
403
404 # prefer binary URLs
405 renv_scope_binding(the, "install_pkg_type", "binary")
406 expect_equal(unname(renv_ppm_transform(binurl)), binurl)
407 expect_equal(unname(renv_ppm_transform(srcurl)), binurl)
408
409 })
410
411 test_that("renv_ppm_is_manylinux detects manylinux URLs", {
412 skip_on_cran()
413
414 expect_true(renv_ppm_is_manylinux("https://p3m.dev/cran/__linux__/manylinux_2_28/latest"))
415 expect_true(renv_ppm_is_manylinux("https://packagemanager.posit.co/cran/__linux__/manylinux_2_28/2024-01-01"))
416 expect_false(renv_ppm_is_manylinux("https://p3m.dev/cran/__linux__/jammy/latest"))
417 expect_false(renv_ppm_is_manylinux("https://p3m.dev/cran/latest"))
418 })
419
420 test_that("manylinux URLs are preserved by renv_ppm_transform", {
421 skip_on_cran()
422 skip_on_os("windows")
423
424 renv_scope_envvars(
425 RENV_PPM_OS = "__linux__",
426 RENV_PPM_PLATFORM = "jammy"
427 )
428
429 manylinux_url <- "https://p3m.dev/cran/__linux__/manylinux_2_28/latest"
430 expect_equal(unname(renv_ppm_transform(manylinux_url)), manylinux_url)
431 })
432
433 test_that("manylinux URLs are normalized when installing source packages", {
434 skip_on_cran()
435 skip_on_os("windows")
436
437 renv_scope_envvars(
438 RENV_PPM_OS = "__linux__",
439 RENV_PPM_PLATFORM = "jammy"
440 )
441
442 # When installing source packages, manylinux URLs should be normalized
443 renv_scope_binding(the, "install_pkg_type", "source")
444
445 manylinux_url <- "https://p3m.dev/cran/__linux__/manylinux_2_28/latest"
446 source_url <- "https://p3m.dev/cran/latest"
447 expect_equal(unname(renv_ppm_transform(manylinux_url)), source_url)
448 })