chore: add header to generated Caddyfile that it's autogenerated

This commit is contained in:
Pasha Sviderski
2025-08-21 08:54:06 +10:00
parent 813c397644
commit c01365b416
2 changed files with 69 additions and 10 deletions
+62 -8
View File
@@ -19,7 +19,10 @@ import (
)
func TestCaddyfileGenerator(t *testing.T) {
caddyfileHeader := `http:// {
caddyfileHeader := `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
}
@@ -185,7 +188,10 @@ https://secure.example.com {
}
func TestCaddyfileGeneratorWithCustomConfigs(t *testing.T) {
caddyfileBase := `http:// {
caddyfileBase := `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
}
@@ -220,12 +226,28 @@ func TestCaddyfileGeneratorWithCustomConfigs(t *testing.T) {
time.Now(),
),
},
want: `# Global Caddy configuration
want: `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
# Global Caddy configuration
{
global directive
}
` + caddyfileBase,
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
}
log
}
(common_proxy) {
# Retry failed requests up to lb_retries times against other available upstreams.
lb_retries 3
# Upstreams are marked unhealthy for fail_duration after a failed request (passive health checking).
fail_duration 30s
}
`,
},
{
name: "regular service with valid custom config",
@@ -386,12 +408,28 @@ web.example.com {
time.Now(),
),
},
want: `# Global config
want: `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
# Global config
{
global directive
}
` + caddyfileBase + `
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
}
log
}
(common_proxy) {
# Retry failed requests up to lb_retries times against other available upstreams.
lb_retries 3
# Upstreams are marked unhealthy for fail_duration after a failed request (passive health checking).
fail_duration 30s
}
http://app.example.com {
reverse_proxy 10.210.0.2:8080 {
import common_proxy
@@ -601,7 +639,10 @@ badconfig.com {
time.Now(),
),
},
want: `# Global config from test machine
want: `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
# Global config from test machine
{
admin off
}
@@ -610,7 +651,20 @@ localhost:8080 {
respond "Admin panel"
}
` + caddyfileBase + `
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
}
log
}
(common_proxy) {
# Retry failed requests up to lb_retries times against other available upstreams.
lb_retries 3
# Upstreams are marked unhealthy for fail_duration after a failed request (passive health checking).
fail_duration 30s
}
http://api.example.com {
reverse_proxy 10.210.1.2:8080 10.210.2.2:8080 10.210.3.2:8080 {
import common_proxy