mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
refactor integration tests under integration/service/create_test.go to use swarm.CreateService
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
This commit is contained in:
parent
fff01bc14d
commit
e9a687146a
1 changed files with 52 additions and 113 deletions
|
@ -34,15 +34,14 @@ func TestCreateServiceMultipleTimes(t *testing.T) {
|
||||||
overlayID := netResp.ID
|
overlayID := netResp.ID
|
||||||
|
|
||||||
var instances uint64 = 4
|
var instances uint64 = 4
|
||||||
serviceSpec := swarmServiceSpec("TestService", instances)
|
|
||||||
serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: overlayName})
|
|
||||||
|
|
||||||
serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{
|
serviceSpec := []swarm.ServiceSpecOpt{
|
||||||
QueryRegistry: false,
|
swarm.ServiceWithReplicas(instances),
|
||||||
})
|
swarm.ServiceWithName("TestService"),
|
||||||
assert.NilError(t, err)
|
swarm.ServiceWithNetwork(overlayName),
|
||||||
|
}
|
||||||
|
|
||||||
serviceID := serviceResp.ID
|
serviceID := swarm.CreateService(t, d, serviceSpec...)
|
||||||
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll)
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll)
|
||||||
|
|
||||||
_, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
|
_, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
|
||||||
|
@ -54,12 +53,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) {
|
||||||
poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll)
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll)
|
||||||
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
||||||
|
|
||||||
serviceResp, err = client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{
|
serviceID2 := swarm.CreateService(t, d, serviceSpec...)
|
||||||
QueryRegistry: false,
|
|
||||||
})
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
serviceID2 := serviceResp.ID
|
|
||||||
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), swarm.ServicePoll)
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), swarm.ServicePoll)
|
||||||
|
|
||||||
err = client.ServiceRemove(context.Background(), serviceID2)
|
err = client.ServiceRemove(context.Background(), serviceID2)
|
||||||
|
@ -100,25 +94,25 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) {
|
||||||
|
|
||||||
// Create Service with the same name
|
// Create Service with the same name
|
||||||
var instances uint64 = 1
|
var instances uint64 = 1
|
||||||
serviceSpec := swarmServiceSpec("top", instances)
|
|
||||||
|
|
||||||
serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: name})
|
serviceID := swarm.CreateService(t, d,
|
||||||
|
swarm.ServiceWithReplicas(instances),
|
||||||
|
swarm.ServiceWithName("top"),
|
||||||
|
swarm.ServiceWithNetwork(name),
|
||||||
|
)
|
||||||
|
|
||||||
service, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{})
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll)
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
poll.WaitOn(t, serviceRunningTasksCount(client, service.ID, instances), swarm.ServicePoll)
|
resp, _, err := client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
|
||||||
|
|
||||||
resp, _, err := client.ServiceInspectWithRaw(context.Background(), service.ID, types.ServiceInspectOptions{})
|
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, is.Equal(n3.ID, resp.Spec.TaskTemplate.Networks[0].Target))
|
assert.Check(t, is.Equal(n3.ID, resp.Spec.TaskTemplate.Networks[0].Target))
|
||||||
|
|
||||||
// Remove Service
|
// Remove Service
|
||||||
err = client.ServiceRemove(context.Background(), service.ID)
|
err = client.ServiceRemove(context.Background(), serviceID)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
// Make sure task has been destroyed.
|
// Make sure task has been destroyed.
|
||||||
poll.WaitOn(t, serviceIsRemoved(client, service.ID), swarm.ServicePoll)
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll)
|
||||||
|
|
||||||
// Remove networks
|
// Remove networks
|
||||||
err = client.NetworkRemove(context.Background(), n3.ID)
|
err = client.NetworkRemove(context.Background(), n3.ID)
|
||||||
|
@ -153,16 +147,11 @@ func TestCreateServiceSecretFileMode(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
var instances uint64 = 1
|
var instances uint64 = 1
|
||||||
serviceSpec := swarmtypes.ServiceSpec{
|
serviceID := swarm.CreateService(t, d,
|
||||||
Annotations: swarmtypes.Annotations{
|
swarm.ServiceWithReplicas(instances),
|
||||||
Name: "TestService",
|
swarm.ServiceWithName("TestService"),
|
||||||
},
|
swarm.ServiceWithCommand([]string{"/bin/sh", "-c", "ls -l /etc/secret || /bin/top"}),
|
||||||
TaskTemplate: swarmtypes.TaskSpec{
|
swarm.ServiceWithSecret(&swarmtypes.SecretReference{
|
||||||
ContainerSpec: &swarmtypes.ContainerSpec{
|
|
||||||
Image: "busybox:latest",
|
|
||||||
Command: []string{"/bin/sh", "-c", "ls -l /etc/secret || /bin/top"},
|
|
||||||
Secrets: []*swarmtypes.SecretReference{
|
|
||||||
{
|
|
||||||
File: &swarmtypes.SecretReferenceFileTarget{
|
File: &swarmtypes.SecretReferenceFileTarget{
|
||||||
Name: "/etc/secret",
|
Name: "/etc/secret",
|
||||||
UID: "0",
|
UID: "0",
|
||||||
|
@ -171,26 +160,13 @@ func TestCreateServiceSecretFileMode(t *testing.T) {
|
||||||
},
|
},
|
||||||
SecretID: secretResp.ID,
|
SecretID: secretResp.ID,
|
||||||
SecretName: "TestSecret",
|
SecretName: "TestSecret",
|
||||||
},
|
}),
|
||||||
},
|
)
|
||||||
},
|
|
||||||
},
|
|
||||||
Mode: swarmtypes.ServiceMode{
|
|
||||||
Replicated: &swarmtypes.ReplicatedService{
|
|
||||||
Replicas: &instances,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
serviceResp, err := client.ServiceCreate(ctx, serviceSpec, types.ServiceCreateOptions{
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll)
|
||||||
QueryRegistry: false,
|
|
||||||
})
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
poll.WaitOn(t, serviceRunningTasksCount(client, serviceResp.ID, instances), swarm.ServicePoll)
|
|
||||||
|
|
||||||
filter := filters.NewArgs()
|
filter := filters.NewArgs()
|
||||||
filter.Add("service", serviceResp.ID)
|
filter.Add("service", serviceID)
|
||||||
tasks, err := client.TaskList(ctx, types.TaskListOptions{
|
tasks, err := client.TaskList(ctx, types.TaskListOptions{
|
||||||
Filters: filter,
|
Filters: filter,
|
||||||
})
|
})
|
||||||
|
@ -207,10 +183,10 @@ func TestCreateServiceSecretFileMode(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, is.Contains(string(content), "-rwxrwxrwx"))
|
assert.Check(t, is.Contains(string(content), "-rwxrwxrwx"))
|
||||||
|
|
||||||
err = client.ServiceRemove(ctx, serviceResp.ID)
|
err = client.ServiceRemove(ctx, serviceID)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
poll.WaitOn(t, serviceIsRemoved(client, serviceResp.ID), swarm.ServicePoll)
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll)
|
||||||
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
poll.WaitOn(t, noTasks(client), swarm.ServicePoll)
|
||||||
|
|
||||||
err = client.SecretRemove(ctx, "TestSecret")
|
err = client.SecretRemove(ctx, "TestSecret")
|
||||||
|
@ -234,16 +210,11 @@ func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
var instances uint64 = 1
|
var instances uint64 = 1
|
||||||
serviceSpec := swarmtypes.ServiceSpec{
|
serviceID := swarm.CreateService(t, d,
|
||||||
Annotations: swarmtypes.Annotations{
|
swarm.ServiceWithName("TestService"),
|
||||||
Name: "TestService",
|
swarm.ServiceWithCommand([]string{"/bin/sh", "-c", "ls -l /etc/config || /bin/top"}),
|
||||||
},
|
swarm.ServiceWithReplicas(instances),
|
||||||
TaskTemplate: swarmtypes.TaskSpec{
|
swarm.ServiceWithConfig(&swarmtypes.ConfigReference{
|
||||||
ContainerSpec: &swarmtypes.ContainerSpec{
|
|
||||||
Image: "busybox:latest",
|
|
||||||
Command: []string{"/bin/sh", "-c", "ls -l /etc/config || /bin/top"},
|
|
||||||
Configs: []*swarmtypes.ConfigReference{
|
|
||||||
{
|
|
||||||
File: &swarmtypes.ConfigReferenceFileTarget{
|
File: &swarmtypes.ConfigReferenceFileTarget{
|
||||||
Name: "/etc/config",
|
Name: "/etc/config",
|
||||||
UID: "0",
|
UID: "0",
|
||||||
|
@ -252,26 +223,13 @@ func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||||
},
|
},
|
||||||
ConfigID: configResp.ID,
|
ConfigID: configResp.ID,
|
||||||
ConfigName: "TestConfig",
|
ConfigName: "TestConfig",
|
||||||
},
|
}),
|
||||||
},
|
)
|
||||||
},
|
|
||||||
},
|
|
||||||
Mode: swarmtypes.ServiceMode{
|
|
||||||
Replicated: &swarmtypes.ReplicatedService{
|
|
||||||
Replicas: &instances,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
serviceResp, err := client.ServiceCreate(ctx, serviceSpec, types.ServiceCreateOptions{
|
poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances))
|
||||||
QueryRegistry: false,
|
|
||||||
})
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
poll.WaitOn(t, serviceRunningTasksCount(client, serviceResp.ID, instances))
|
|
||||||
|
|
||||||
filter := filters.NewArgs()
|
filter := filters.NewArgs()
|
||||||
filter.Add("service", serviceResp.ID)
|
filter.Add("service", serviceID)
|
||||||
tasks, err := client.TaskList(ctx, types.TaskListOptions{
|
tasks, err := client.TaskList(ctx, types.TaskListOptions{
|
||||||
Filters: filter,
|
Filters: filter,
|
||||||
})
|
})
|
||||||
|
@ -288,35 +246,16 @@ func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, is.Contains(string(content), "-rwxrwxrwx"))
|
assert.Check(t, is.Contains(string(content), "-rwxrwxrwx"))
|
||||||
|
|
||||||
err = client.ServiceRemove(ctx, serviceResp.ID)
|
err = client.ServiceRemove(ctx, serviceID)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
poll.WaitOn(t, serviceIsRemoved(client, serviceResp.ID))
|
poll.WaitOn(t, serviceIsRemoved(client, serviceID))
|
||||||
poll.WaitOn(t, noTasks(client))
|
poll.WaitOn(t, noTasks(client))
|
||||||
|
|
||||||
err = client.ConfigRemove(ctx, "TestConfig")
|
err = client.ConfigRemove(ctx, "TestConfig")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func swarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec {
|
|
||||||
return swarmtypes.ServiceSpec{
|
|
||||||
Annotations: swarmtypes.Annotations{
|
|
||||||
Name: name,
|
|
||||||
},
|
|
||||||
TaskTemplate: swarmtypes.TaskSpec{
|
|
||||||
ContainerSpec: &swarmtypes.ContainerSpec{
|
|
||||||
Image: "busybox:latest",
|
|
||||||
Command: []string{"/bin/top"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Mode: swarmtypes.ServiceMode{
|
|
||||||
Replicated: &swarmtypes.ReplicatedService{
|
|
||||||
Replicas: &replicas,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result {
|
func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result {
|
||||||
return func(log poll.LogT) poll.Result {
|
return func(log poll.LogT) poll.Result {
|
||||||
filter := filters.NewArgs()
|
filter := filters.NewArgs()
|
||||||
|
|
Loading…
Reference in a new issue