mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
client: rename ConfigListResult.Configs to ConfigListResult.Items
Also consolidate the options with the method. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -8,14 +8,18 @@ import (
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
)
|
||||
|
||||
// ConfigListResult holds the result from the ConfigList method.
|
||||
// ConfigListOptions holds parameters to list configs
|
||||
type ConfigListOptions struct {
|
||||
Filters Filters
|
||||
}
|
||||
|
||||
// ConfigListResult holds the result from the [client.ConfigList] method.
|
||||
type ConfigListResult struct {
|
||||
Configs []swarm.Config
|
||||
Items []swarm.Config
|
||||
}
|
||||
|
||||
// ConfigList returns the list of configs.
|
||||
func (cli *Client) ConfigList(ctx context.Context, options ConfigListOptions) (ConfigListResult, error) {
|
||||
var out ConfigListResult
|
||||
query := url.Values{}
|
||||
options.Filters.updateURLValues(query)
|
||||
|
||||
@@ -25,7 +29,8 @@ func (cli *Client) ConfigList(ctx context.Context, options ConfigListOptions) (C
|
||||
return ConfigListResult{}, err
|
||||
}
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&out.Configs)
|
||||
var out ConfigListResult
|
||||
err = json.NewDecoder(resp.Body).Decode(&out.Items)
|
||||
if err != nil {
|
||||
return ConfigListResult{}, err
|
||||
}
|
||||
|
||||
@@ -83,6 +83,6 @@ func TestConfigList(t *testing.T) {
|
||||
|
||||
result, err := client.ConfigList(context.Background(), listCase.options)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Len(result.Configs, 2))
|
||||
assert.Check(t, is.Len(result.Items, 2))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,13 @@ package client
|
||||
|
||||
import "context"
|
||||
|
||||
type ConfigRemoveOptions struct{}
|
||||
type ConfigRemoveOptions struct {
|
||||
// Add future optional parameters here
|
||||
}
|
||||
|
||||
type ConfigRemoveResult struct{}
|
||||
type ConfigRemoveResult struct {
|
||||
// Add future fields here
|
||||
}
|
||||
|
||||
// ConfigRemove removes a config.
|
||||
func (cli *Client) ConfigRemove(ctx context.Context, id string, options ConfigRemoveOptions) (ConfigRemoveResult, error) {
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package client
|
||||
|
||||
// ConfigListOptions holds parameters to list configs
|
||||
type ConfigListOptions struct {
|
||||
Filters Filters
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func TestConfigList(t *testing.T) {
|
||||
// This test case is ported from the original TestConfigsEmptyList
|
||||
result, err := c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(len(result.Configs), 0))
|
||||
assert.Check(t, is.Equal(len(result.Items), 0))
|
||||
|
||||
testName0 := "test0-" + t.Name()
|
||||
testName1 := "test1-" + t.Name()
|
||||
@@ -69,9 +69,9 @@ func TestConfigList(t *testing.T) {
|
||||
config1ID := createConfig(ctx, t, c, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"})
|
||||
|
||||
// test by `config ls`
|
||||
entries, err := c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
res, err := c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.DeepEqual(configNamesFromList(entries.Configs), testNames))
|
||||
assert.Check(t, is.DeepEqual(configNamesFromList(res.Items), testNames))
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
@@ -107,11 +107,11 @@ func TestConfigList(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
ctx := testutil.StartSpan(ctx, t)
|
||||
entries, err = c.ConfigList(ctx, client.ConfigListOptions{
|
||||
res, err = c.ConfigList(ctx, client.ConfigListOptions{
|
||||
Filters: tc.filters,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.DeepEqual(configNamesFromList(entries.Configs), tc.expected))
|
||||
assert.Check(t, is.DeepEqual(configNamesFromList(res.Items), tc.expected))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -360,18 +360,18 @@ func TestConfigCreateResolve(t *testing.T) {
|
||||
fakeName := configID
|
||||
fakeID := createConfig(ctx, t, c, fakeName, []byte("fake foo"), nil)
|
||||
|
||||
entries, err := c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
res, err := c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Contains(configNamesFromList(entries.Configs), configName))
|
||||
assert.Assert(t, is.Contains(configNamesFromList(entries.Configs), fakeName))
|
||||
assert.Assert(t, is.Contains(configNamesFromList(res.Items), configName))
|
||||
assert.Assert(t, is.Contains(configNamesFromList(res.Items), fakeName))
|
||||
|
||||
_, err = c.ConfigRemove(ctx, configID, client.ConfigRemoveOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Fake one will remain
|
||||
entries, err = c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
res, err = c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.DeepEqual(configNamesFromList(entries.Configs), []string{fakeName}))
|
||||
assert.Assert(t, is.DeepEqual(configNamesFromList(res.Items), []string{fakeName}))
|
||||
|
||||
// Remove based on name prefix of the fake one
|
||||
// (which is the same as the ID of foo one) should not work
|
||||
@@ -381,16 +381,16 @@ func TestConfigCreateResolve(t *testing.T) {
|
||||
// - Partial ID (prefix)
|
||||
_, err = c.ConfigRemove(ctx, configID[:5], client.ConfigRemoveOptions{})
|
||||
assert.Assert(t, err != nil)
|
||||
entries, err = c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
res, err = c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.DeepEqual(configNamesFromList(entries.Configs), []string{fakeName}))
|
||||
assert.Assert(t, is.DeepEqual(configNamesFromList(res.Items), []string{fakeName}))
|
||||
|
||||
// Remove based on ID prefix of the fake one should succeed
|
||||
_, err = c.ConfigRemove(ctx, fakeID[:5], client.ConfigRemoveOptions{})
|
||||
assert.NilError(t, err)
|
||||
entries, err = c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
res, err = c.ConfigList(ctx, client.ConfigListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Equal(0, len(entries.Configs)))
|
||||
assert.Assert(t, is.Equal(0, len(res.Items)))
|
||||
}
|
||||
|
||||
func configNamesFromList(entries []swarmtypes.Config) []string {
|
||||
|
||||
@@ -33,7 +33,7 @@ func (d *Daemon) ListConfigs(t testing.TB) []swarm.Config {
|
||||
|
||||
result, err := cli.ConfigList(context.Background(), client.ConfigListOptions{})
|
||||
assert.NilError(t, err)
|
||||
return result.Configs
|
||||
return result.Items
|
||||
}
|
||||
|
||||
// GetConfig returns a swarm config identified by the specified id
|
||||
|
||||
13
vendor/github.com/moby/moby/client/config_list.go
generated
vendored
13
vendor/github.com/moby/moby/client/config_list.go
generated
vendored
@@ -8,14 +8,18 @@ import (
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
)
|
||||
|
||||
// ConfigListResult holds the result from the ConfigList method.
|
||||
// ConfigListOptions holds parameters to list configs
|
||||
type ConfigListOptions struct {
|
||||
Filters Filters
|
||||
}
|
||||
|
||||
// ConfigListResult holds the result from the [client.ConfigList] method.
|
||||
type ConfigListResult struct {
|
||||
Configs []swarm.Config
|
||||
Items []swarm.Config
|
||||
}
|
||||
|
||||
// ConfigList returns the list of configs.
|
||||
func (cli *Client) ConfigList(ctx context.Context, options ConfigListOptions) (ConfigListResult, error) {
|
||||
var out ConfigListResult
|
||||
query := url.Values{}
|
||||
options.Filters.updateURLValues(query)
|
||||
|
||||
@@ -25,7 +29,8 @@ func (cli *Client) ConfigList(ctx context.Context, options ConfigListOptions) (C
|
||||
return ConfigListResult{}, err
|
||||
}
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&out.Configs)
|
||||
var out ConfigListResult
|
||||
err = json.NewDecoder(resp.Body).Decode(&out.Items)
|
||||
if err != nil {
|
||||
return ConfigListResult{}, err
|
||||
}
|
||||
|
||||
8
vendor/github.com/moby/moby/client/config_remove.go
generated
vendored
8
vendor/github.com/moby/moby/client/config_remove.go
generated
vendored
@@ -2,9 +2,13 @@ package client
|
||||
|
||||
import "context"
|
||||
|
||||
type ConfigRemoveOptions struct{}
|
||||
type ConfigRemoveOptions struct {
|
||||
// Add future optional parameters here
|
||||
}
|
||||
|
||||
type ConfigRemoveResult struct{}
|
||||
type ConfigRemoveResult struct {
|
||||
// Add future fields here
|
||||
}
|
||||
|
||||
// ConfigRemove removes a config.
|
||||
func (cli *Client) ConfigRemove(ctx context.Context, id string, options ConfigRemoveOptions) (ConfigRemoveResult, error) {
|
||||
|
||||
6
vendor/github.com/moby/moby/client/swarm_config_list_options.go
generated
vendored
6
vendor/github.com/moby/moby/client/swarm_config_list_options.go
generated
vendored
@@ -1,6 +0,0 @@
|
||||
package client
|
||||
|
||||
// ConfigListOptions holds parameters to list configs
|
||||
type ConfigListOptions struct {
|
||||
Filters Filters
|
||||
}
|
||||
Reference in New Issue
Block a user