Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests #60

Merged
merged 11 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on:
pull_request:
push:
branches: ["main"]

jobs:
test:
name: Integration tests
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Build container image
run: docker build -t nexus_allowlist:latest .

- name: Start service
run: docker compose up -d

- name: Wait for Nexus to start
run: sleep 120

- name: Show nexus allowlist container logs
run: docker compose logs allowlist

- name: Show nexus container logs
run: docker compose logs nexus

- name: Run tests
working-directory: integration_tests
run: ./test.sh
1 change: 1 addition & 0 deletions allowlists/cran.allowlist
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cli
data.table
remotes
7 changes: 4 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
---
version: "3"
services:
nexus:
container_name: nexus
image: sonatype/nexus3:3.71.0
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./nexus-data:/nexus-data
- nexus-data:/nexus-data
restart: always
allowlist:
container_name: allowlist
Expand All @@ -21,7 +20,7 @@ services:
# ENTR_FALLBACK: "yes"
volumes:
- ./allowlists:/allowlists
- ./nexus-data:/nexus-data
- nexus-data:/nexus-data
restart: always
reverse-proxy:
container_name: reverse-proxy
Expand All @@ -30,3 +29,5 @@ services:
- "8080:80"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
volumes:
nexus-data:
6 changes: 6 additions & 0 deletions integration_tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM bats/bats

RUN apk add --no-cache --update python3 py3-pip R
RUN mkdir -p /root/.config/pip
COPY pip.conf /root/.config/pip/pip.conf
COPY Rprofile /root/.Rprofile
9 changes: 9 additions & 0 deletions integration_tests/Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.First <- function(){
.libPaths("/root/rpackages")
}

local({
r <- getOption("repos")
r["CRAN"] <- "http://localhost:8080/repository/cran-proxy"
options(repos=r)
})
3 changes: 3 additions & 0 deletions integration_tests/pip.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[global]
index = http://localhost:8080/repository/pypi-proxy/pypi
index-url = http://localhost:8080/repository/pypi-proxy/simple
8 changes: 8 additions & 0 deletions integration_tests/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /usr/bin/env bash
docker build -t nexus_allowlist_bats:latest .
docker run \
--rm \
-v "$PWD/tests:/code" \
--network host \
nexus_allowlist_bats:latest \
/code
35 changes: 35 additions & 0 deletions integration_tests/tests/cran.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
setup() {
mkdir /root/rpackages
}

teardown() {
rm -rf /root/rpackages
}

@test "Install data.table" {
run Rscript -e 'install.packages("data.table")'
[[ "$output" == *"package ‘data.table’ successfully unpacked and MD5 sums checked"* ]]
}

@test "Install archived version of data.table" {
run Rscript -e 'packagename <- "data.table"
version <- "1.13.0" # or 1.12.0
packageurl <- paste0(contrib.url(getOption("repos")), "/Archive/", packagename, "/", packagename, "_", version, ".tar.gz")
install.packages(packageurl, repos=NULL, type="source")
'
[[ "$output" == *"package ‘data.table’ successfully unpacked and MD5 sums checked"* ]]
}

@test "Install archived version of data.table using remotes" {
run Rscript -e '
install.packages("remotes")
remotes::install_version("data.table", version = "1.13.0")
'
[[ "$output" == *"package ‘data.table’ successfully unpacked and MD5 sums checked"* ]]
}

@test "Install ggplot2" {
run Rscript -e 'install.packages("ggplot2")'
[[ "$output" == *"download of package ‘ggplot2’ failed"* ]]
[[ "$output" == *"HTTP status was '403 Forbidden'"* ]]
}
20 changes: 20 additions & 0 deletions integration_tests/tests/pypi.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
setup () {
python3 -m venv /root/venv
. /root/venv/bin/activate
}

teardown() {
deactivate
rm -rf /root/venv
}

@test "Install numpy" {
pip install numpy
}

@test "Install mkdocs" {
bats_require_minimum_version 1.5.0
run ! pip install mkdocs
[ "$status" -eq 1 ]
[[ "$output" == *"HTTP error 403"* ]]
}