mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00

This was done with something along the lines of: ``` mv internal/test testutil pushd testutil/; grep -IRl "package test" | xargs -I '{}' sed -i -e 's|package test|package testutil|g' {}; popd mv internal/testutil/*.go testutil/ && rm -rf internal/ grep -IRl "github.com\/docker\/docker\/internal\/test" | xargs -I '{}' sed -i -e 's|github.com/docker/docker/internal/test|github.com/docker/docker/test|g' {} goimports . ``` I also modified the basic plugin path in testutil/fixtures/plugin. Signed-off-by: Sam Whited <sam@samwhited.com>
82 lines
2.1 KiB
Go
82 lines
2.1 KiB
Go
package daemon
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/swarm"
|
|
"github.com/docker/docker/testutil"
|
|
"gotest.tools/assert"
|
|
)
|
|
|
|
// ConfigConstructor defines a swarm config constructor
|
|
type ConfigConstructor func(*swarm.Config)
|
|
|
|
// CreateConfig creates a config given the specified spec
|
|
func (d *Daemon) CreateConfig(t assert.TestingT, configSpec swarm.ConfigSpec) string {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
scr, err := cli.ConfigCreate(context.Background(), configSpec)
|
|
assert.NilError(t, err)
|
|
return scr.ID
|
|
}
|
|
|
|
// ListConfigs returns the list of the current swarm configs
|
|
func (d *Daemon) ListConfigs(t assert.TestingT) []swarm.Config {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
configs, err := cli.ConfigList(context.Background(), types.ConfigListOptions{})
|
|
assert.NilError(t, err)
|
|
return configs
|
|
}
|
|
|
|
// GetConfig returns a swarm config identified by the specified id
|
|
func (d *Daemon) GetConfig(t assert.TestingT, id string) *swarm.Config {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
config, _, err := cli.ConfigInspectWithRaw(context.Background(), id)
|
|
assert.NilError(t, err)
|
|
return &config
|
|
}
|
|
|
|
// DeleteConfig removes the swarm config identified by the specified id
|
|
func (d *Daemon) DeleteConfig(t assert.TestingT, id string) {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
err := cli.ConfigRemove(context.Background(), id)
|
|
assert.NilError(t, err)
|
|
}
|
|
|
|
// UpdateConfig updates the swarm config identified by the specified id
|
|
// Currently, only label update is supported.
|
|
func (d *Daemon) UpdateConfig(t assert.TestingT, id string, f ...ConfigConstructor) {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
config := d.GetConfig(t, id)
|
|
for _, fn := range f {
|
|
fn(config)
|
|
}
|
|
|
|
err := cli.ConfigUpdate(context.Background(), config.ID, config.Version, config.Spec)
|
|
assert.NilError(t, err)
|
|
}
|