mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
b37c214e3c
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>
84 lines
2.1 KiB
Go
84 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"
|
|
)
|
|
|
|
// SecretConstructor defines a swarm secret constructor
|
|
type SecretConstructor func(*swarm.Secret)
|
|
|
|
// CreateSecret creates a secret given the specified spec
|
|
func (d *Daemon) CreateSecret(t assert.TestingT, secretSpec swarm.SecretSpec) string {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
scr, err := cli.SecretCreate(context.Background(), secretSpec)
|
|
assert.NilError(t, err)
|
|
|
|
return scr.ID
|
|
}
|
|
|
|
// ListSecrets returns the list of the current swarm secrets
|
|
func (d *Daemon) ListSecrets(t assert.TestingT) []swarm.Secret {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
secrets, err := cli.SecretList(context.Background(), types.SecretListOptions{})
|
|
assert.NilError(t, err)
|
|
return secrets
|
|
}
|
|
|
|
// GetSecret returns a swarm secret identified by the specified id
|
|
func (d *Daemon) GetSecret(t assert.TestingT, id string) *swarm.Secret {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
secret, _, err := cli.SecretInspectWithRaw(context.Background(), id)
|
|
assert.NilError(t, err)
|
|
return &secret
|
|
}
|
|
|
|
// DeleteSecret removes the swarm secret identified by the specified id
|
|
func (d *Daemon) DeleteSecret(t assert.TestingT, id string) {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
err := cli.SecretRemove(context.Background(), id)
|
|
assert.NilError(t, err)
|
|
}
|
|
|
|
// UpdateSecret updates the swarm secret identified by the specified id
|
|
// Currently, only label update is supported.
|
|
func (d *Daemon) UpdateSecret(t assert.TestingT, id string, f ...SecretConstructor) {
|
|
if ht, ok := t.(testutil.HelperT); ok {
|
|
ht.Helper()
|
|
}
|
|
cli := d.NewClientT(t)
|
|
defer cli.Close()
|
|
|
|
secret := d.GetSecret(t, id)
|
|
for _, fn := range f {
|
|
fn(secret)
|
|
}
|
|
|
|
err := cli.SecretUpdate(context.Background(), secret.ID, secret.Version, secret.Spec)
|
|
|
|
assert.NilError(t, err)
|
|
}
|