forked from moby/moby
/
config.go
72 lines (58 loc) · 1.83 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package daemon
import (
"context"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"gotest.tools/v3/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 testing.TB, configSpec swarm.ConfigSpec) string {
t.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 testing.TB) []swarm.Config {
t.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 testing.TB, id string) *swarm.Config {
t.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 testing.TB, id string) {
t.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 testing.TB, id string, f ...ConfigConstructor) {
t.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)
}