Skip to content
Draft
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
41 changes: 31 additions & 10 deletions .config/starte2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,41 @@ set -eu
# CI does not add /usr/bin to $PATH for some reason, which means we
# lack docker
export PATH="${PATH}:/usr/bin"
# Assume the default profile on older nextest versions
NEXTEST_PROFILE="${NEXTEST_PROFILE:-default}"

# If we're running in CI, we are in a docker container, so containers
# launched by us do not bind-mount into local directories. Instead, we
# copy the test environment to the host, so that we can bind-mount
# from there.

TEST_ENV="$(realpath "$(dirname "$0")/../tests/environment")"
export ENV_PATH="$TEST_ENV"

if [ "$NEXTEST_PROFILE" = "ci" ]; then
cp -r tests/environment "$RUNNER_TEMP/test-env"
TEST_ENV="$RUNNER_TEMP/test-env"
ENV_PATH="/home/runner/work/_temp/test-env"
export ENV_PATH
fi

# Make sure the containers can write some files that need to be shared
touch tests/environment/zitadel/service-user.json
chmod a+rw tests/environment/zitadel/service-user.json
touch "$TEST_ENV/zitadel/service-user.json"
chmod a+rw "$TEST_ENV/zitadel/service-user.json"

# We only take down ldap if the cert are too old and need regeneration
# We only take down ldap if the certs are too old and need regeneration
ldap_down=""
file_creation=$(date -r ./tests/environment/certs/ca.crt +%s || echo 0)
if [ $(( $(date +%s) - $file_creation )) -gt 2160000 ]; # 25 days old?
then
ldap_down="-v ldap"
file_creation=$(date -r "$TEST_ENV/certs/ca.crt" +%s || echo 0)
if [ $(($(date +%s) - file_creation)) -gt $((25 * 24 * 60 * 60)) ]; then
ldap_down="-v ldap"
fi

# Shut down any still running test-setup first
docker compose --project-directory ./tests/environment down -v test-setup $ldap_down || true
docker compose --project-directory ./tests/environment up --wait \
|| (docker compose --project-directory ./tests/environment logs test-setup; exit 1)
docker compose --project-directory "$TEST_ENV" down -v test-setup "$ldap_down" || true
docker compose --project-directory "$TEST_ENV" up --wait || (
docker compose --project-directory "$TEST_ENV" logs test-setup
exit 1
)

echo "TEST_ENV=$TEST_ENV" >> "$NEXTEST_ENV"
cat "$NEXTEST_ENV"
92 changes: 2 additions & 90 deletions .github/workflows/rust-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,101 +8,13 @@ on:
pull_request:
branches: [ "*" ]

env:
CARGO_TERM_COLOR: always

# Make sure there is no pipeline running uselessly.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# Defined CI jobs.
jobs:
simple-checks:
container: docker-oss.nexus.famedly.de/rust-container:nightly
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v4

- uses: famedly/backend-build-workflows/.github/actions/rust-prepare@main
with:
gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}}
gitlab_user: ${{ secrets.GITLAB_USER }}
gitlab_pass: ${{ secrets.GITLAB_PASS }}

- name: Caching
uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352
with:
cache-on-failure: true
cache-all-crates: true

- name: Rustfmt
shell: bash
run: cargo +${NIGHTLY_VERSION} fmt -- --check

- name: Clippy
shell: bash
run: cargo +${NIGHTLY_VERSION} clippy --workspace --all-targets -- -D warnings

- name: Doc-test
shell: bash
run: cargo +${NIGHTLY_VERSION} test --doc --workspace --verbose

- name: Udeps
shell: bash
run: cargo +${NIGHTLY_VERSION} udeps

- name: Typos
shell: bash
run: typos --exclude '*.key' --exclude '*.crt' --exclude '*.csr' --exclude '*.srl'

tests:
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v4

- uses: famedly/backend-build-workflows/.github/actions/rust-prepare@main
with:
gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}}
gitlab_user: ${{ secrets.GITLAB_USER }}
gitlab_pass: ${{ secrets.GITLAB_PASS }}

- name: Add llvm-tools rust component
run: rustup component add llvm-tools-preview --toolchain stable-x86_64-unknown-linux-gnu

- name: Caching
uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352
with:
cache-on-failure: true
cache-all-crates: true

- name: Install additional cargo tooling
shell: bash
run: cargo install cargo-nextest cargo-llvm-cov --locked

- name: Test
timeout-minutes: 20
shell: bash
run: |
docker compose --project-directory ./tests/environment down -v
cargo llvm-cov nextest --profile ci --workspace --lcov --output-path lcov.info

- name: Get docker logs on failure
shell: bash
if: failure()
run: |
docker compose --project-directory ./tests/environment logs

- name: Codecov - Upload coverage
uses: codecov/codecov-action@v4
with:
token: ${{secrets.CODECOV_TOKEN}}
files: lcov.info

- name: Codecov - Upload test results
uses: codecov/test-results-action@v1
with:
token: ${{secrets.CODECOV_TOKEN}}

uses: famedly/backend-build-workflows/.github/workflows/rust-workflow.yml@ccb800fdb716ff3b8459f19bb9ceb56544d0798e
secrets: inherit
20 changes: 13 additions & 7 deletions tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![cfg(test)]
/// E2E integration tests
use std::{collections::HashSet, path::Path, pin::pin, time::Duration};
use std::{collections::HashSet, path::PathBuf, pin::pin, time::Duration};

use base64::{engine::general_purpose, Engine as _};
use famedly_sync::{
Expand Down Expand Up @@ -2060,13 +2060,15 @@ async fn cleanup_test_users(config: &Config) {

/// Get the module's test environment config
async fn ldap_config() -> &'static Config {
let config_dir = std::env::var("TEST_ENV").map(PathBuf::from).expect("Cannot find config dir");

CONFIG_WITH_LDAP
.get_or_init(|| async {
let mut config = Config::new(Path::new("tests/environment/config.yaml"))
let mut config = Config::new(&config_dir.join("config.yaml"))
.expect("failed to parse test env file");

config.sources.ldap = serde_yaml::from_slice(
&std::fs::read(Path::new("tests/environment/ldap-config.template.yaml"))
&std::fs::read(config_dir.join("ldap-config.template.yaml"))
.expect("failed to read ldap config file"),
)
.expect("failed to parse ldap config");
Expand All @@ -2078,13 +2080,15 @@ async fn ldap_config() -> &'static Config {

/// Get the module's test environment config
async fn ukt_config() -> &'static Config {
let config_dir = std::env::var("TEST_ENV").map(PathBuf::from).expect("Cannot find config dir");

CONFIG_WITH_UKT
.get_or_init(|| async {
let mut config = Config::new(Path::new("tests/environment/config.yaml"))
let mut config = Config::new(&config_dir.join("config.yaml"))
.expect("failed to parse test env file");

config.sources.ukt = serde_yaml::from_slice(
&std::fs::read(Path::new("tests/environment/ukt-config.template.yaml"))
&std::fs::read(config_dir.join("ukt-config.template.yaml"))
.expect("failed to read ukt config file"),
)
.expect("failed to parse ukt config");
Expand All @@ -2096,13 +2100,15 @@ async fn ukt_config() -> &'static Config {

/// Get the module's test environment config
async fn csv_config() -> &'static Config {
let config_dir = std::env::var("TEST_ENV").map(PathBuf::from).expect("Cannot find config dir");

CONFIG_WITH_CSV
.get_or_init(|| async {
let mut config = Config::new(Path::new("tests/environment/config.yaml"))
let mut config = Config::new(&config_dir.join("config.yaml"))
.expect("failed to parse test env file");

config.sources.csv = serde_yaml::from_slice(
&std::fs::read(Path::new("tests/environment/csv-config.template.yaml"))
&std::fs::read(config_dir.join("csv-config.template.yaml"))
.expect("failed to read csv config file"),
)
.expect("failed to parse csv config");
Expand Down
10 changes: 5 additions & 5 deletions tests/environment/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
image: alpine/openssl:3.3.2
volumes:
- type: bind
source: ./certs
source: ${ENV_PATH}/certs
target: /certs
entrypoint: /certs/generate-certs.sh

Expand All @@ -20,7 +20,7 @@ services:
- LDAP_TLS_VERIFY_CLIENTS=try
volumes:
- type: bind
source: ./certs
source: ${ENV_PATH}/certs
target: /certs
read_only: true
depends_on:
Expand All @@ -34,10 +34,10 @@ services:
entrypoint: /environment/test-setup.sh
volumes:
- type: bind
source: ./
source: ${ENV_PATH}/
target: /environment
- type: bind
source: ./config.template.yaml
source: ${ENV_PATH}/config.template.yaml
target: /config.template.yaml
read_only: true
healthcheck:
Expand All @@ -59,7 +59,7 @@ services:
- 8080:8080
volumes:
- type: bind
source: ./zitadel/
source: ${ENV_PATH}/zitadel/
target: /zitadel-config/
depends_on:
db:
Expand Down