Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
atheo89 committed Jan 31, 2024
1 parent 879392e commit e038763
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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=<container-image-name>" ; \
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
Expand Down

0 comments on commit e038763

Please sign in to comment.