github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/internal/test/daemon/config.go (about) 1 package daemon 2 3 import ( 4 "context" 5 6 "github.com/docker/docker/api/types" 7 "github.com/docker/docker/api/types/swarm" 8 "github.com/gotestyourself/gotestyourself/assert" 9 ) 10 11 // ConfigConstructor defines a swarm config constructor 12 type ConfigConstructor func(*swarm.Config) 13 14 // CreateConfig creates a config given the specified spec 15 func (d *Daemon) CreateConfig(t assert.TestingT, configSpec swarm.ConfigSpec) string { 16 cli := d.NewClientT(t) 17 defer cli.Close() 18 19 scr, err := cli.ConfigCreate(context.Background(), configSpec) 20 assert.NilError(t, err) 21 return scr.ID 22 } 23 24 // ListConfigs returns the list of the current swarm configs 25 func (d *Daemon) ListConfigs(t assert.TestingT) []swarm.Config { 26 cli := d.NewClientT(t) 27 defer cli.Close() 28 29 configs, err := cli.ConfigList(context.Background(), types.ConfigListOptions{}) 30 assert.NilError(t, err) 31 return configs 32 } 33 34 // GetConfig returns a swarm config identified by the specified id 35 func (d *Daemon) GetConfig(t assert.TestingT, id string) *swarm.Config { 36 cli := d.NewClientT(t) 37 defer cli.Close() 38 39 config, _, err := cli.ConfigInspectWithRaw(context.Background(), id) 40 assert.NilError(t, err) 41 return &config 42 } 43 44 // DeleteConfig removes the swarm config identified by the specified id 45 func (d *Daemon) DeleteConfig(t assert.TestingT, id string) { 46 cli := d.NewClientT(t) 47 defer cli.Close() 48 49 err := cli.ConfigRemove(context.Background(), id) 50 assert.NilError(t, err) 51 } 52 53 // UpdateConfig updates the swarm config identified by the specified id 54 // Currently, only label update is supported. 55 func (d *Daemon) UpdateConfig(t assert.TestingT, id string, f ...ConfigConstructor) { 56 cli := d.NewClientT(t) 57 defer cli.Close() 58 59 config := d.GetConfig(t, id) 60 for _, fn := range f { 61 fn(config) 62 } 63 64 err := cli.ConfigUpdate(context.Background(), config.ID, config.Version, config.Spec) 65 assert.NilError(t, err) 66 }