integration/config: TestTemplatedConfig: simplify task code

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-08-19 14:40:38 +02:00
parent ec78112edd
commit dd67b4794e
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -271,29 +271,12 @@ func TestTemplatedConfig(t *testing.T) {
swarm.ServiceWithName("svc"),
)
var tasks []swarmtypes.Task
getRunningTasks := func(log poll.LogT) poll.Result {
tasks = swarm.GetRunningTasks(t, c, serviceID)
if len(tasks) > 0 {
return poll.Success()
}
return poll.Continue("task still waiting")
}
poll.WaitOn(t, getRunningTasks, swarm.ServicePoll, poll.WithTimeout(1*time.Minute))
poll.WaitOn(t, swarm.RunningTasksCount(c, serviceID, 1), swarm.ServicePoll, poll.WithTimeout(1*time.Minute))
task := tasks[0]
getTask := func(log poll.LogT) poll.Result {
if task.NodeID == "" || (task.Status.ContainerStatus == nil || task.Status.ContainerStatus.ContainerID == "") {
task, _, _ = c.TaskInspectWithRaw(context.Background(), task.ID)
}
if task.NodeID != "" && task.Status.ContainerStatus != nil && task.Status.ContainerStatus.ContainerID != "" {
return poll.Success()
}
return poll.Continue("task still waiting")
}
poll.WaitOn(t, getTask, swarm.ServicePoll, poll.WithTimeout(1*time.Minute))
tasks := swarm.GetRunningTasks(t, c, serviceID)
assert.Assert(t, len(tasks) > 0, "no running tasks found for service %s", serviceID)
attach := swarm.ExecTask(t, d, task, types.ExecConfig{
attach := swarm.ExecTask(t, d, tasks[0], types.ExecConfig{
Cmd: []string{"/bin/cat", "/" + templatedConfigName},
AttachStdout: true,
AttachStderr: true,
@ -304,7 +287,7 @@ func TestTemplatedConfig(t *testing.T) {
"this is a config\n"
assertAttachedStream(t, attach, expect)
attach = swarm.ExecTask(t, d, task, types.ExecConfig{
attach = swarm.ExecTask(t, d, tasks[0], types.ExecConfig{
Cmd: []string{"mount"},
AttachStdout: true,
AttachStderr: true,