From e03876325c4a34bebabe1ff0d3dda58838ad7fbf Mon Sep 17 00:00:00 2001 From: atheo89 Date: Tue, 30 Jan 2024 09:03:42 +0100 Subject: [PATCH] Add test cases --- Makefile | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b5bcb3459..7274517ce 100644 --- a/Makefile +++ b/Makefile @@ -428,25 +428,75 @@ validate-codeserver-image: bin/kubectl fi; \ done ; \ +# R Script (test.R) +define R_SCRIPT + # Set a seed for reproducibility + set.seed(123) + + # Generate a random dataset + x <- rnorm(100) + data <- data.frame( + x = x, + y = 2 * x + rnorm(100) + ) + if ("x" %in% colnames(data) && is.numeric(data$x) && + "y" %in% colnames(data) && is.numeric(data$y)) { + # Compute basic statistics + mean_x <- mean(data$x, na.rm = TRUE) + mean_y <- mean(data$y, na.rm = TRUE) + correlation <- cor(data$x, data$y, use = "complete.obs") + # Print the statistics + cat("Mean of x:", mean_x, "\n") + cat("Mean of y:", mean_y, "\n") + cat("Correlation between x and y:", correlation, "\n") + + } else { + cat("Error: Columns 'x' and 'y' must be numeric and exist in the dataset.\n") + } +endef + +export R_SCRIPT + .PHONY: validate-rstudio-image validate-rstudio-image: bin/kubectl $(eval NOTEBOOK_NAME := $(subst .,-,$(subst cuda-,,$*))) - $(info # Running tests for $(NOTEBOOK_NAME) code-server image...) + $(info # Running tests for $(NOTEBOOK_NAME) RStudio image...) $(KUBECTL_BIN) wait --for=condition=ready pod rstudio-pod --timeout=300s @required_commands=$(REQUIRED_R_STUDIO_IMAGE_COMMANDS) ; \ if [[ $$image == "" ]] ; then \ echo "Usage: make validate-rstudio-image image=" ; \ exit 1 ; \ fi ; \ + echo "=> Checking container image $$image for package intallation..." ; \ + $(KUBECTL_BIN) exec -it rstudio-pod -- mkdir -p /opt/app-root/src/R/temp-library > /dev/null 2>&1 ; \ + $(KUBECTL_BIN) exec rstudio-pod -- R -e "install.packages('tinytex', lib='/opt/app-root/src/R/temp-library')" > /dev/null 2>&1 ; \ + if [ $$? -eq 0 ]; then \ + echo "Tinytex installation successful!"; \ + else \ + echo "Error: Tinytex installation failed."; \ + fi; \ for cmd in $$required_commands ; do \ echo "=> Checking container image $$image for $$cmd..." ; \ $(KUBECTL_BIN) exec rstudio-pod which $$cmd > /dev/null 2>&1 ; \ - if [ $$? -ne 0 ]; then \ - echo "ERROR: Container image $$image does not meet criteria for command: $$cmd" ; \ + if [ $$? -eq 0 ]; then \ + echo "$$cmd executed successfuly!"; \ + else \ + echo "ERROR: Container image $$image does not meet criteria for command: $$cmd" ; \ fail=1; \ continue; \ fi; \ done ; \ + echo "=> Creating R file and executing on the container..."; \ + echo "$$R_SCRIPT" > test.R > /dev/null 2>&1; \ + $(KUBECTL_BIN) cp test.R rstudio-pod:/opt/app-root/src/test.R > /dev/null 2>&1; \ + $(KUBECTL_BIN) exec rstudio-pod -- Rscript /opt/app-root/src/test.R > /dev/null 2>&1; \ + if [ $$? -eq 0 ]; then \ + echo "R script executed successfully!"; \ + rm test.R ; \ + else \ + echo "Error: R script failed."; \ + fi; \ + # This is only for the workflow action .PHONY: refresh-pipfilelock-files