From 4ce0ad9715186fea26d7c1a1fae10af8929bb200 Mon Sep 17 00:00:00 2001 From: Josh Wolf Date: Mon, 18 Nov 2024 20:12:02 -0500 Subject: [PATCH] Add test(s) for caddy (#34470) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 generated for as part of [expanding package test coverage](https://github.com/wolfi-dev/os/issues/13623) Signed-off-by: Josh Wolf --- caddy.yaml | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/caddy.yaml b/caddy.yaml index a423103d38f..24e45f31142 100644 --- a/caddy.yaml +++ b/caddy.yaml @@ -60,8 +60,102 @@ update: use-tag: true test: + environment: + contents: + packages: + - curl + - netcat-openbsd + - procps + - coreutils pipeline: - # AUTOGENERATED - - runs: | + - name: "Verify binary and version" + runs: | + caddy version caddy --version - caddy --help + - name: "Check basic help output" + runs: | + caddy help + caddy list-modules + - name: "Test basic HTTP server" + uses: test/daemon-check-output + with: + setup: | + echo "http://localhost:2020 { + respond \"Hello, Wolfi!\" + }" > test.Caddyfile + start: caddy run --config test.Caddyfile + expected_output: "serving initial configuration" + error_strings: | + "msg":"error" + "level":"error" + "panic" + "fatal" + failed + Error: + error: + denied + - name: "Test static file serving" + uses: test/daemon-check-output + with: + setup: | + mkdir -p webroot + echo "Static Test" > webroot/test.txt + echo "http://localhost:2021 { + root * webroot + file_server + }" > static.Caddyfile + start: caddy run --config static.Caddyfile + expected_output: "serving initial configuration" + error_strings: | + "msg":"error" + "level":"error" + "panic" + "fatal" + failed + Error: + error: + denied + post: | + curl -s http://localhost:2021/test.txt | grep -q "Static Test" + - name: "Test module loading and functionality" + uses: test/daemon-check-output + with: + setup: | + cat < modules.Caddyfile + http://localhost:2024 { + route /headers { + header Content-Type "text/plain" + respond "Headers Test" + } + route /reverse/* { + uri strip_prefix /reverse + reverse_proxy http://localhost:2024 { + header_up X-Real-IP {remote_host} + } + } + route /compress { + encode gzip + respond "Compression Test" + } + } + EOF + start: caddy run --config modules.Caddyfile + expected_output: "serving initial configuration" + error_strings: | + "msg":"error" + "level":"error" + "panic" + "fatal" + failed + Error: + error: + denied + post: | + # Test header module + curl -s -i http://localhost:2024/headers | grep -q "Content-Type: text/plain" + + # Test reverse_proxy module + curl -s http://localhost:2024/reverse/headers | grep -q "Headers Test" + + # Test compression module + curl -s -H "Accept-Encoding: gzip" http://localhost:2024/compress | grep -q "Compression Test"