chore: update comments in generated Caddyfile

This commit is contained in:
Pasha Sviderski
2025-08-21 13:14:54 +10:00
parent c01365b416
commit b437659678
2 changed files with 62 additions and 29 deletions
+41 -19
View File
@@ -19,9 +19,10 @@ import (
)
func TestCaddyfileGenerator(t *testing.T) {
caddyfileHeader := `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
caddyfileHeader := `# This file is autogenerated by Uncloud based on the configuration of running services.
# Do not edit manually. Any manual changes will be overwritten on the next update.
# Health check endpoint to verify Caddy reachability on this machine.
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
@@ -54,6 +55,8 @@ http:// {
newContainerRecord(newContainer("10.210.0.2", "app.example.com:8080/http"), "mach1"),
},
want: caddyfileHeader + `
# Sites generated from service ports.
http://app.example.com {
reverse_proxy 10.210.0.2:8080 {
import common_proxy
@@ -69,6 +72,8 @@ http://app.example.com {
newContainerRecord(newContainer("10.210.0.3", "app.example.com:8080/http"), "mach1"),
},
want: caddyfileHeader + `
# Sites generated from service ports.
http://app.example.com {
reverse_proxy 10.210.0.2:8080 10.210.0.3:8080 {
import common_proxy
@@ -83,6 +88,8 @@ http://app.example.com {
newContainerRecord(newContainer("10.210.0.2", "secure.example.com:8000/https"), "mach1"),
},
want: caddyfileHeader + `
# Sites generated from service ports.
https://secure.example.com {
reverse_proxy 10.210.0.2:8000 {
import common_proxy
@@ -121,6 +128,8 @@ https://secure.example.com {
),
},
want: caddyfileHeader + `
# Sites generated from service ports.
http://app.example.com {
reverse_proxy 10.210.0.2:8080 10.210.0.3:8080 10.210.0.5:8080 {
import common_proxy
@@ -188,9 +197,10 @@ https://secure.example.com {
}
func TestCaddyfileGeneratorWithCustomConfigs(t *testing.T) {
caddyfileBase := `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
caddyfileBase := `# This file is autogenerated by Uncloud based on the configuration of running services.
# Do not edit manually. Any manual changes will be overwritten on the next update.
# Health check endpoint to verify Caddy reachability on this machine.
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
@@ -226,14 +236,16 @@ http:// {
time.Now(),
),
},
want: `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
want: `# This file is autogenerated by Uncloud based on the configuration of running services.
# Do not edit manually. Any manual changes will be overwritten on the next update.
# User-defined global config from service 'caddy'.
# Global Caddy configuration
{
global directive
}
# Health check endpoint to verify Caddy reachability on this machine.
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
@@ -264,7 +276,7 @@ web.example.com {
),
},
want: caddyfileBase + `
# Service: web
# User-defined config for service 'web'.
# Custom config for web service
web.example.com {
reverse_proxy web:3000
@@ -368,12 +380,12 @@ bad.example.com {
),
},
want: caddyfileBase + `
# Service: api
# User-defined config for service 'api'.
api.example.com {
reverse_proxy api:8080
}
# Service: web
# User-defined config for service 'web'.
web.example.com {
reverse_proxy web:3000
}
@@ -408,14 +420,16 @@ web.example.com {
time.Now(),
),
},
want: `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
want: `# This file is autogenerated by Uncloud based on the configuration of running services.
# Do not edit manually. Any manual changes will be overwritten on the next update.
# User-defined global config from service 'caddy'.
# Global config
{
global directive
}
# Health check endpoint to verify Caddy reachability on this machine.
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
@@ -430,6 +444,8 @@ http:// {
fail_duration 30s
}
# Sites generated from service ports.
http://app.example.com {
reverse_proxy 10.210.0.2:8080 {
import common_proxy
@@ -437,7 +453,7 @@ http://app.example.com {
log
}
# Service: api
# User-defined config for service 'api'.
api.example.com {
reverse_proxy api:8000
}
@@ -463,6 +479,8 @@ api.example.com {
),
},
want: caddyfileBase + `
# Sites generated from service ports.
http://api.example.com {
reverse_proxy 10.210.0.3:8080 {
import common_proxy
@@ -470,7 +488,7 @@ http://api.example.com {
log
}
# Service: web
# User-defined config for service 'web'.
web.example.com {
reverse_proxy 10.210.0.2
}
@@ -501,7 +519,7 @@ new.example.com {
),
},
want: caddyfileBase + `
# Service: web
# User-defined config for service 'web'.
# New config
new.example.com {
respond "New"
@@ -639,9 +657,10 @@ badconfig.com {
time.Now(),
),
},
want: `# This file is autogenerated by Uncloud. Do not edit manually.
# Any manual changes will be overwritten on the next update.
want: `# This file is autogenerated by Uncloud based on the configuration of running services.
# Do not edit manually. Any manual changes will be overwritten on the next update.
# User-defined global config from service 'caddy'.
# Global config from test machine
{
admin off
@@ -651,6 +670,7 @@ localhost:8080 {
respond "Admin panel"
}
# Health check endpoint to verify Caddy reachability on this machine.
http:// {
handle /.uncloud-verify {
respond "test-machine-id" 200
@@ -665,6 +685,8 @@ http:// {
fail_duration 30s
}
# Sites generated from service ports.
http://api.example.com {
reverse_proxy 10.210.1.2:8080 10.210.2.2:8080 10.210.3.2:8080 {
import common_proxy
@@ -686,7 +708,7 @@ http://web.example.com {
log
}
# Service: db
# User-defined config for service 'db'.
# DB admin panel
dbadmin.example.com {
basicauth {
@@ -695,7 +717,7 @@ dbadmin.example.com {
reverse_proxy 10.210.1.4:5432
}
# Service: gateway
# User-defined config for service 'gateway'.
# Testing different upstream template functions
gateway.example.com {
# Current service upstreams (gateway)
@@ -729,7 +751,7 @@ gateway.example.com {
}
}
# Service: web
# User-defined config for service 'web'.
# Web service config v2 (most recent)
web-v2.example.com {
reverse_proxy 10.210.1.3:8080 10.210.3.3:8080 10.210.2.3:8080