add templates tests

Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
This commit is contained in:
Mohammed Al Sahaf 2026-06-06 22:28:48 +03:00
parent 9853a97fee
commit 966f8b6bdf
No known key found for this signature in database

View file

@ -0,0 +1,168 @@
# Configure Caddy with templates directive
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
templates
respond "Request path: \{\{.OriginalReq.URL.Path}}"
}
```
# templates processes template syntax
GET https://localhost:9443/test/path
[Options]
insecure: true
HTTP 200
[Asserts]
body == "Request path: /test/path"
# Configure Caddy with templates and file_server
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
root * {{indexed_root}}
templates
file_server
}
```
# templates doesn't process non-template files
GET https://localhost:9443/index.txt
[Options]
insecure: true
HTTP 200
[Asserts]
body == "index.txt"
# Configure Caddy with templates and placeholders
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
templates
respond "Method: \{\{.Req.Method}}, Host: \{\{.Req.Host}}"
}
```
# templates exposes request properties
GET https://localhost:9443
[Options]
insecure: true
HTTP 200
[Asserts]
body == "Method: GET, Host: localhost:9443"
# POST method is accessible in templates
POST https://localhost:9443
[Options]
insecure: true
HTTP 200
[Asserts]
body == "Method: POST, Host: localhost:9443"
# Configure Caddy with templates and functions
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
templates
respond "\{\{upper \"hello world\"}}"
}
```
# templates provides utility functions
GET https://localhost:9443
[Options]
insecure: true
HTTP 200
[Asserts]
body == "HELLO WORLD"
# Configure Caddy with templates conditionals
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
templates
respond "\{\{if eq .Req.Method \"GET\"}}GET method\{\{else}}Other method\{\{end}}"
}
```
# templates supports conditionals
GET https://localhost:9443
[Options]
insecure: true
HTTP 200
[Asserts]
body == "GET method"
# templates conditional for other methods
POST https://localhost:9443
[Options]
insecure: true
HTTP 200
[Asserts]
body == "Other method"
# Configure Caddy with templates and environment variables
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
templates
respond "Path: \{\{env \"PATH\"}}"
}
```
# templates can access environment variables
GET https://localhost:9443
[Options]
insecure: true
HTTP 200
[Asserts]
body contains "Path:"
body contains "/"