chore: caddy client to get caddy config

This commit is contained in:
Pasha Sviderski
2025-08-22 15:58:21 +10:00
parent 75fdbaf2f4
commit 3cda5cc564
6 changed files with 55 additions and 7 deletions
+43 -3
View File
@@ -271,7 +271,7 @@ func TestDeployment(t *testing.T) {
}
})
deployment, err := cli.NewCaddyDeployment("", api.Placement{})
deployment, err := cli.NewCaddyDeployment("", "", api.Placement{})
require.NoError(t, err)
_, err = deployment.Run(ctx)
@@ -284,6 +284,12 @@ func TestDeployment(t *testing.T) {
ctr := svc.Containers[0].Container
assert.Regexp(t, `^caddy:2\.\d+\.\d+$`, ctr.Config.Image)
config, err := cli.Caddy.GetConfig(ctx, nil)
require.NoError(t, err)
assert.Contains(t, config.Caddyfile, "# This file is autogenerated by Uncloud")
assert.Contains(t, config.Caddyfile, "handle /.uncloud-verify")
})
t.Run("caddy with machine placement", func(t *testing.T) {
@@ -295,7 +301,7 @@ func TestDeployment(t *testing.T) {
})
// Deploy to machine #0.
deployment, err := cli.NewCaddyDeployment("", api.Placement{
deployment, err := cli.NewCaddyDeployment("", "", api.Placement{
Machines: []string{c.Machines[0].Name},
})
require.NoError(t, err)
@@ -313,7 +319,7 @@ func TestDeployment(t *testing.T) {
// initialContainerID := svc.Containers[0].Container.ID
// Deploy to all machines without a placement constraint.
deployment, err = cli.NewCaddyDeployment(image, api.Placement{})
deployment, err = cli.NewCaddyDeployment(image, "", api.Placement{})
require.NoError(t, err)
_, err = deployment.Run(ctx)
@@ -332,6 +338,40 @@ func TestDeployment(t *testing.T) {
// assert.True(t, containers.Contains(initialContainerID), "Expected initial container to remain")
})
t.Run("caddy with custom config", func(t *testing.T) {
t.Cleanup(func() {
err := cli.RemoveService(ctx, client.CaddyServiceName)
if !errors.Is(err, api.ErrNotFound) {
require.NoError(t, err)
}
})
caddyfile := `{
debug
}
myapp.example.com {
reverse_proxy myapp:8000
}`
deployment, err := cli.NewCaddyDeployment("", caddyfile, api.Placement{})
require.NoError(t, err)
_, err = deployment.Run(ctx)
require.NoError(t, err)
svc, err := cli.InspectService(ctx, client.CaddyServiceName)
require.NoError(t, err)
assertServiceMatchesSpec(t, svc, deployment.Spec)
config, err := cli.Caddy.GetConfig(ctx, nil)
require.NoError(t, err)
assert.Contains(t, config.Caddyfile, "# This file is autogenerated by Uncloud")
assert.Contains(t, config.Caddyfile, "handle /.uncloud-verify")
assert.Contains(t, config.Caddyfile, caddyfile,
"Expected user-defined global Caddy config to be included in the Caddyfile")
})
t.Run("replicated", func(t *testing.T) {
t.Parallel()