2018-04-18 10:18:53 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-09-23 08:23:01 -04:00
|
|
|
"testing"
|
2018-04-18 10:18:53 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/client"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/poll"
|
2018-04-18 10:18:53 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// PluginIsRunning provides a poller to check if the specified plugin is running
|
2019-09-23 08:23:01 -04:00
|
|
|
func (d *Daemon) PluginIsRunning(t testing.TB, name string) func(poll.LogT) poll.Result {
|
2019-02-06 18:33:07 -05:00
|
|
|
return withClient(t, d, withPluginInspect(name, func(plugin *types.Plugin, t poll.LogT) poll.Result {
|
2018-04-18 10:18:53 -04:00
|
|
|
if plugin.Enabled {
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
return poll.Continue("plugin %q is not enabled", name)
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginIsNotRunning provides a poller to check if the specified plugin is not running
|
2019-09-23 08:23:01 -04:00
|
|
|
func (d *Daemon) PluginIsNotRunning(t testing.TB, name string) func(poll.LogT) poll.Result {
|
2019-02-06 18:33:07 -05:00
|
|
|
return withClient(t, d, withPluginInspect(name, func(plugin *types.Plugin, t poll.LogT) poll.Result {
|
2018-04-18 10:18:53 -04:00
|
|
|
if !plugin.Enabled {
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
return poll.Continue("plugin %q is enabled", name)
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginIsNotPresent provides a poller to check if the specified plugin is not present
|
2019-09-23 08:23:01 -04:00
|
|
|
func (d *Daemon) PluginIsNotPresent(t testing.TB, name string) func(poll.LogT) poll.Result {
|
2019-02-06 18:33:07 -05:00
|
|
|
return withClient(t, d, func(c client.APIClient, t poll.LogT) poll.Result {
|
2018-04-18 10:18:53 -04:00
|
|
|
_, _, err := c.PluginInspectWithRaw(context.Background(), name)
|
|
|
|
if client.IsErrNotFound(err) {
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return poll.Error(err)
|
|
|
|
}
|
2018-05-13 16:24:04 -04:00
|
|
|
return poll.Continue("plugin %q exists", name)
|
2018-04-18 10:18:53 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginReferenceIs provides a poller to check if the specified plugin has the specified reference
|
2019-09-23 08:23:01 -04:00
|
|
|
func (d *Daemon) PluginReferenceIs(t testing.TB, name, expectedRef string) func(poll.LogT) poll.Result {
|
2019-02-06 18:33:07 -05:00
|
|
|
return withClient(t, d, withPluginInspect(name, func(plugin *types.Plugin, t poll.LogT) poll.Result {
|
2018-04-18 10:18:53 -04:00
|
|
|
if plugin.PluginReference == expectedRef {
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
return poll.Continue("plugin %q reference is not %q", name, expectedRef)
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
func withPluginInspect(name string, f func(*types.Plugin, poll.LogT) poll.Result) func(client.APIClient, poll.LogT) poll.Result {
|
|
|
|
return func(c client.APIClient, t poll.LogT) poll.Result {
|
|
|
|
plugin, _, err := c.PluginInspectWithRaw(context.Background(), name)
|
|
|
|
if client.IsErrNotFound(err) {
|
|
|
|
return poll.Continue("plugin %q not found", name)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return poll.Error(err)
|
|
|
|
}
|
|
|
|
return f(plugin, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-23 08:23:01 -04:00
|
|
|
func withClient(t testing.TB, d *Daemon, f func(client.APIClient, poll.LogT) poll.Result) func(poll.LogT) poll.Result {
|
2019-02-06 18:33:07 -05:00
|
|
|
return func(pt poll.LogT) poll.Result {
|
|
|
|
c := d.NewClientT(t)
|
|
|
|
return f(c, pt)
|
2018-04-18 10:18:53 -04:00
|
|
|
}
|
|
|
|
}
|