chore: refactor Caddyfile generator to accept a validator

This commit is contained in:
Pasha Sviderski
2025-08-18 18:48:32 +10:00
parent 455174ccb0
commit 93fef88fac
4 changed files with 76 additions and 21 deletions
@@ -8,10 +8,10 @@ import (
"github.com/stretchr/testify/require"
)
func TestGenerateCaddyfile(t *testing.T) {
func TestCaddyfileGenerator(t *testing.T) {
caddyfileHeader := `http:// {
handle /.uncloud-verify {
respond "verification-response-body" 200
respond "test-machine-id" 200
}
log
}
@@ -24,6 +24,10 @@ func TestGenerateCaddyfile(t *testing.T) {
}
`
generator := &CaddyfileGenerator{
MachineID: "test-machine-id",
}
tests := []struct {
name string
containers []api.ServiceContainer
@@ -182,7 +186,7 @@ http://app.example.com {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config, err := GenerateCaddyfile(tt.containers, "verification-response-body")
config, err := generator.Generate(tt.containers)
if tt.wantErr {
assert.Error(t, err)