From 75d1e697a5aa742237a854175f784814ef164e3c Mon Sep 17 00:00:00 2001 From: Nishant Totla Date: Mon, 6 Nov 2017 15:47:58 -0800 Subject: [PATCH] Fix error message for TestSwarmVolumePlugin Signed-off-by: Nishant Totla --- .../integration-cli/daemon/daemon_swarm.go | 17 +++++++++++++++++ .../docker_cli_swarm_unix_test.go | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/components/engine/integration-cli/daemon/daemon_swarm.go b/components/engine/integration-cli/daemon/daemon_swarm.go index c37c7269f5..bd1ada0b42 100644 --- a/components/engine/integration-cli/daemon/daemon_swarm.go +++ b/components/engine/integration-cli/daemon/daemon_swarm.go @@ -198,6 +198,23 @@ func (d *Swarm) CheckServiceTasksInState(service string, state swarm.TaskState, } } +// CheckServiceTasksInStateWithError returns the number of tasks with a matching state, +// and optional message substring. +func (d *Swarm) CheckServiceTasksInStateWithError(service string, state swarm.TaskState, errorMessage string) func(*check.C) (interface{}, check.CommentInterface) { + return func(c *check.C) (interface{}, check.CommentInterface) { + tasks := d.GetServiceTasks(c, service) + var count int + for _, task := range tasks { + if task.Status.State == state { + if errorMessage == "" || strings.Contains(task.Status.Err, errorMessage) { + count++ + } + } + } + return count, nil + } +} + // CheckServiceRunningTasks returns the number of running tasks for the specified service func (d *Swarm) CheckServiceRunningTasks(service string) func(*check.C) (interface{}, check.CommentInterface) { return d.CheckServiceTasksInState(service, swarm.TaskStateRunning, "") diff --git a/components/engine/integration-cli/docker_cli_swarm_unix_test.go b/components/engine/integration-cli/docker_cli_swarm_unix_test.go index 16b27ef19b..3b890bcc69 100644 --- a/components/engine/integration-cli/docker_cli_swarm_unix_test.go +++ b/components/engine/integration-cli/docker_cli_swarm_unix_test.go @@ -19,7 +19,7 @@ func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) { c.Assert(err, checker.IsNil, check.Commentf(out)) // Make sure task stays pending before plugin is available - waitAndAssert(c, defaultReconciliationTimeout, d.CheckServiceTasksInState("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals, 1) + waitAndAssert(c, defaultReconciliationTimeout, d.CheckServiceTasksInStateWithError("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals, 1) plugin := newVolumePlugin(c, "customvolumedriver") defer plugin.Close()