Skip to content

Commit

Permalink
Merge pull request #870 from jstourac/testProxy
Browse files Browse the repository at this point in the history
RHOAIENG-17251: add a test for the proxy env configuration in RStudio + some other minor changes
  • Loading branch information
openshift-merge-bot[bot] authored Jan 28, 2025
2 parents 22f1d9c + 51e022e commit 84de282
Showing 1 changed file with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import json
import logging
import pathlib
import pytest_subtests
import subprocess
import tempfile
import textwrap
from typing import TYPE_CHECKING
from typing import NamedTuple, TYPE_CHECKING

import allure
import pytest
Expand All @@ -21,7 +22,7 @@
class TestRStudioImage:
"""Tests for RStudio Workbench images in this repository."""

APP_ROOT_HOME = "/opt/app-root/src/"
APP_ROOT_HOME = "/opt/app-root/src"

@allure.issue("RHOAIENG-17256")
def test_rmd_to_pdf_rendering(self, image: str) -> None:
Expand Down Expand Up @@ -99,6 +100,43 @@ def test_rmd_to_pdf_rendering(self, image: str) -> None:
finally:
docker_utils.NotebookContainer(container).stop(timeout=0)

@allure.issue("RHOAIENG-16604")
def test_http_proxy_env_propagates(self, image: str, subtests: pytest_subtests.plugin.SubTests) -> None:
"""
This checks that the lowercased proxy configuration is propagated into the RStudio
environment so that the appropriate values are then accepted and followed.
"""
skip_if_not_rstudio_image(image)

class TestCase(NamedTuple):
name: str
name_lc: str
value: str

test_cases: list[TestCase] = [
TestCase("HTTP_PROXY", "http_proxy", "http://localhost:8080"),
TestCase("HTTPS_PROXY", "https_proxy", "https://localhost:8443"),
TestCase("NO_PROXY", "no_proxy", "google.com"),
]

container = WorkbenchContainer(image=image, user=1000, group_add=[0])
for tc in test_cases:
container.with_env(tc.name, tc.value)

try:
# We need to wait for the IDE to be completely loaded so that the envs are processed properly.
container.start(wait_for_readiness=True)

# Once the RStudio IDE is fully up and running, the processed envs should includ also lowercased proxy configs.
for tc in test_cases:
with subtests.test(tc.name):
output = check_output(
container,
f"/usr/bin/R --quiet --no-echo -e 'Sys.getenv(\"{tc.name_lc}\")'")
assert '"' + tc.value + '"' in output
finally:
docker_utils.NotebookContainer(container).stop(timeout=0)


def check_call(container: WorkbenchContainer, cmd: str) -> int:
"""Like subprocess.check_output, but in a container."""
Expand Down

0 comments on commit 84de282

Please sign in to comment.