mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
fix: spec validation when name is empty, race in e2e tests
This commit is contained in:
@@ -337,7 +337,7 @@ func (d *Deployment) Validate(ctx context.Context) error {
|
|||||||
return fmt.Errorf("invalid service spec: %w", err)
|
return fmt.Errorf("invalid service spec: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.Service == nil {
|
if d.Service == nil && d.Spec.Name != "" {
|
||||||
svc, err := d.cli.InspectService(ctx, d.Spec.Name)
|
svc, err := d.cli.InspectService(ctx, d.Spec.Name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
d.Service = &svc
|
d.Service = &svc
|
||||||
|
|||||||
+15
-10
@@ -40,14 +40,18 @@ func TestDeployment(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, _ := createTestCluster(t, clusterName, ucind.CreateClusterOptions{Machines: 3}, true)
|
c, _ := createTestCluster(t, clusterName, ucind.CreateClusterOptions{Machines: 3}, true)
|
||||||
|
|
||||||
cli, err := c.Machines[0].Connect(ctx)
|
cli, cErr := c.Machines[0].Connect(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, cErr)
|
||||||
|
|
||||||
t.Run("global auto-generated name", func(t *testing.T) {
|
t.Run("global auto-generated name", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
name := "" // auto-generated and updated
|
name := "" // auto-generated and updated
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
|
if name == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err := cli.RemoveService(ctx, name)
|
err := cli.RemoveService(ctx, name)
|
||||||
if !errors.Is(err, api.ErrNotFound) {
|
if !errors.Is(err, api.ErrNotFound) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -70,7 +74,7 @@ func TestDeployment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
deployment := cli.NewDeployment(spec, nil)
|
deployment := cli.NewDeployment(spec, nil)
|
||||||
|
|
||||||
err = deployment.Validate(ctx)
|
err := deployment.Validate(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
plan, err := deployment.Plan(ctx)
|
plan, err := deployment.Plan(ctx)
|
||||||
@@ -236,7 +240,7 @@ func TestDeployment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
deployment := cli.NewDeployment(spec, nil)
|
deployment := cli.NewDeployment(spec, nil)
|
||||||
|
|
||||||
_, err = deployment.Run(ctx)
|
_, err := deployment.Run(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
svc, err := cli.InspectService(ctx, name)
|
svc, err := cli.InspectService(ctx, name)
|
||||||
@@ -542,7 +546,7 @@ myapp.example.com {
|
|||||||
}
|
}
|
||||||
deployment := cli.NewDeployment(spec, nil)
|
deployment := cli.NewDeployment(spec, nil)
|
||||||
|
|
||||||
err = deployment.Validate(ctx)
|
err := deployment.Validate(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
plan, err := deployment.Plan(ctx)
|
plan, err := deployment.Plan(ctx)
|
||||||
@@ -709,7 +713,7 @@ myapp.example.com {
|
|||||||
|
|
||||||
deployment := cli.NewDeployment(spec, nil)
|
deployment := cli.NewDeployment(spec, nil)
|
||||||
|
|
||||||
_, err = deployment.Run(ctx)
|
_, err := deployment.Run(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Verify service has 2 containers on machines 0 and 1.
|
// Verify service has 2 containers on machines 0 and 1.
|
||||||
@@ -1090,7 +1094,7 @@ myapp.example.com {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d := deploy.NewDeployment(cli, spec, nil)
|
d := deploy.NewDeployment(cli, spec, nil)
|
||||||
_, err = d.Run(ctx)
|
_, err := d.Run(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
svc, err := cli.InspectService(ctx, serviceName)
|
svc, err := cli.InspectService(ctx, serviceName)
|
||||||
@@ -1128,7 +1132,7 @@ myapp.example.com {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d := deploy.NewDeployment(cli, spec, nil)
|
d := deploy.NewDeployment(cli, spec, nil)
|
||||||
_, err = d.Run(ctx)
|
_, err := d.Run(ctx)
|
||||||
require.Error(t, err, "Global deployment should fail when required volume doesn't exist")
|
require.Error(t, err, "Global deployment should fail when required volume doesn't exist")
|
||||||
require.Contains(t, err.Error(), "no machines available")
|
require.Contains(t, err.Error(), "no machines available")
|
||||||
})
|
})
|
||||||
@@ -1270,7 +1274,7 @@ myapp.example.com {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deployment := cli.NewDeployment(spec, nil)
|
deployment := cli.NewDeployment(spec, nil)
|
||||||
_, err = deployment.Run(ctx)
|
_, err := deployment.Run(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
svc, err := cli.InspectService(ctx, serviceName)
|
svc, err := cli.InspectService(ctx, serviceName)
|
||||||
@@ -2086,7 +2090,8 @@ func TestServiceLifecycle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assertNoDNSErrors := func(t *testing.T, dnsOutput string) {
|
assertNoDNSErrors := func(t *testing.T, dnsOutput string) {
|
||||||
assert.NotContains(t, dnsOutput, "server can't find", "DNS query should not contain NXDOMAIN/SERVFAIL errors")
|
assert.NotContains(t, dnsOutput, "server can't find",
|
||||||
|
"DNS query should not contain NXDOMAIN/SERVFAIL errors")
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("service name resolves to all container IPs", func(t *testing.T) {
|
t.Run("service name resolves to all container IPs", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user