2019-03-28 14:06:06 -05:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2025-03-08 18:25:20 +01:00
|
|
|
"github.com/docker/cli/opts/swarmopts"
|
2019-03-28 14:06:06 -05:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2020-02-22 18:12:14 +01:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2019-03-28 14:06:06 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// fakeConfigAPIClientList is used to let us pass a closure as a
|
|
|
|
// ConfigAPIClient, to use as ConfigList. for all the other methods in the
|
|
|
|
// interface, it does nothing, not even return an error, so don't use them
|
2025-05-19 13:55:23 +02:00
|
|
|
type fakeConfigAPIClientList func(context.Context, swarm.ConfigListOptions) ([]swarm.Config, error)
|
2019-03-28 14:06:06 -05:00
|
|
|
|
2025-05-19 13:55:23 +02:00
|
|
|
func (f fakeConfigAPIClientList) ConfigList(ctx context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) {
|
2019-03-28 14:06:06 -05:00
|
|
|
return f(ctx, opts)
|
|
|
|
}
|
|
|
|
|
2025-05-19 13:55:23 +02:00
|
|
|
func (fakeConfigAPIClientList) ConfigCreate(_ context.Context, _ swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) {
|
|
|
|
return swarm.ConfigCreateResponse{}, nil
|
2019-03-28 14:06:06 -05:00
|
|
|
}
|
|
|
|
|
cli/command/service: fix "unused-receiver" linting
cli/command/service/update_test.go:511:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretCreate(context.Context, swarm.SecretSpec) (types.SecretCreateResponse, error) {
^
cli/command/service/update_test.go:515:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretRemove(context.Context, string) error {
^
cli/command/service/update_test.go:519:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretInspectWithRaw(context.Context, string) (swarm.Secret, []byte, error) {
^
cli/command/service/generic_resource_opts.go:46: line-length-limit: line is 206 characters, out of limit 200 (revive)
return nil, fmt.Errorf("invalid generic-resource request `%s=%s`, Named Generic Resources is not supported for service create or update", res.NamedResourceSpec.Kind, res.NamedResourceSpec.Value)
cli/command/service/create_test.go:24:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigCreate(_ context.Context, _ swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
^
cli/command/service/logs.go:320:7: unused-receiver: method receiver 'lw' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (lw *logWriter) parseContext(details map[string]string) (logContext, error) {
^
cli/command/service/opts.go:45:7: unused-receiver: method receiver 'i' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (i *Uint64Opt) Type() string {
^
cli/command/service/update_test.go:523:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretUpdate(context.Context, string, swarm.Version, swarm.SecretSpec) error {
^
cli/command/service/create_test.go:28:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigRemove(_ context.Context, _ string) error {
^
cli/command/service/opts.go:70:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f *floatValue) Type() string {
^
cli/command/service/opts.go:117:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (o *placementPrefOpts) Type() string {
^
cli/command/service/create_test.go:32:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigInspectWithRaw(_ context.Context, _ string) (swarm.Config, []byte, error) {
^
cli/command/service/create_test.go:36:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ConfigSpec) error {
^
cli/command/service/opts.go:135:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s *ShlexOpt) Type() string {
^
cli/command/service/opts.go:366:7: unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (c *credentialSpecOpt) Type() string {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-17 14:27:56 +01:00
|
|
|
func (fakeConfigAPIClientList) ConfigRemove(_ context.Context, _ string) error {
|
2019-03-28 14:06:06 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
cli/command/service: fix "unused-receiver" linting
cli/command/service/update_test.go:511:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretCreate(context.Context, swarm.SecretSpec) (types.SecretCreateResponse, error) {
^
cli/command/service/update_test.go:515:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretRemove(context.Context, string) error {
^
cli/command/service/update_test.go:519:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretInspectWithRaw(context.Context, string) (swarm.Secret, []byte, error) {
^
cli/command/service/generic_resource_opts.go:46: line-length-limit: line is 206 characters, out of limit 200 (revive)
return nil, fmt.Errorf("invalid generic-resource request `%s=%s`, Named Generic Resources is not supported for service create or update", res.NamedResourceSpec.Kind, res.NamedResourceSpec.Value)
cli/command/service/create_test.go:24:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigCreate(_ context.Context, _ swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
^
cli/command/service/logs.go:320:7: unused-receiver: method receiver 'lw' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (lw *logWriter) parseContext(details map[string]string) (logContext, error) {
^
cli/command/service/opts.go:45:7: unused-receiver: method receiver 'i' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (i *Uint64Opt) Type() string {
^
cli/command/service/update_test.go:523:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretUpdate(context.Context, string, swarm.Version, swarm.SecretSpec) error {
^
cli/command/service/create_test.go:28:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigRemove(_ context.Context, _ string) error {
^
cli/command/service/opts.go:70:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f *floatValue) Type() string {
^
cli/command/service/opts.go:117:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (o *placementPrefOpts) Type() string {
^
cli/command/service/create_test.go:32:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigInspectWithRaw(_ context.Context, _ string) (swarm.Config, []byte, error) {
^
cli/command/service/create_test.go:36:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ConfigSpec) error {
^
cli/command/service/opts.go:135:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s *ShlexOpt) Type() string {
^
cli/command/service/opts.go:366:7: unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (c *credentialSpecOpt) Type() string {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-17 14:27:56 +01:00
|
|
|
func (fakeConfigAPIClientList) ConfigInspectWithRaw(_ context.Context, _ string) (swarm.Config, []byte, error) {
|
2019-03-28 14:06:06 -05:00
|
|
|
return swarm.Config{}, nil, nil
|
|
|
|
}
|
|
|
|
|
cli/command/service: fix "unused-receiver" linting
cli/command/service/update_test.go:511:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretCreate(context.Context, swarm.SecretSpec) (types.SecretCreateResponse, error) {
^
cli/command/service/update_test.go:515:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretRemove(context.Context, string) error {
^
cli/command/service/update_test.go:519:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretInspectWithRaw(context.Context, string) (swarm.Secret, []byte, error) {
^
cli/command/service/generic_resource_opts.go:46: line-length-limit: line is 206 characters, out of limit 200 (revive)
return nil, fmt.Errorf("invalid generic-resource request `%s=%s`, Named Generic Resources is not supported for service create or update", res.NamedResourceSpec.Kind, res.NamedResourceSpec.Value)
cli/command/service/create_test.go:24:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigCreate(_ context.Context, _ swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
^
cli/command/service/logs.go:320:7: unused-receiver: method receiver 'lw' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (lw *logWriter) parseContext(details map[string]string) (logContext, error) {
^
cli/command/service/opts.go:45:7: unused-receiver: method receiver 'i' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (i *Uint64Opt) Type() string {
^
cli/command/service/update_test.go:523:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s secretAPIClientMock) SecretUpdate(context.Context, string, swarm.Version, swarm.SecretSpec) error {
^
cli/command/service/create_test.go:28:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigRemove(_ context.Context, _ string) error {
^
cli/command/service/opts.go:70:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f *floatValue) Type() string {
^
cli/command/service/opts.go:117:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (o *placementPrefOpts) Type() string {
^
cli/command/service/create_test.go:32:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigInspectWithRaw(_ context.Context, _ string) (swarm.Config, []byte, error) {
^
cli/command/service/create_test.go:36:7: unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (f fakeConfigAPIClientList) ConfigUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ConfigSpec) error {
^
cli/command/service/opts.go:135:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s *ShlexOpt) Type() string {
^
cli/command/service/opts.go:366:7: unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (c *credentialSpecOpt) Type() string {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-17 14:27:56 +01:00
|
|
|
func (fakeConfigAPIClientList) ConfigUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ConfigSpec) error {
|
2019-03-28 14:06:06 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestSetConfigsWithCredSpecAndConfigs tests that the setConfigs function for
|
|
|
|
// create correctly looks up the right configs, and correctly handles the
|
|
|
|
// credentialSpec
|
|
|
|
func TestSetConfigsWithCredSpecAndConfigs(t *testing.T) {
|
|
|
|
// we can't directly access the internal fields of the ConfigOpt struct, so
|
|
|
|
// we need to let it do the parsing
|
2025-03-08 18:25:20 +01:00
|
|
|
configOpt := &swarmopts.ConfigOpt{}
|
|
|
|
assert.Check(t, configOpt.Set("bar"))
|
2019-03-28 14:06:06 -05:00
|
|
|
opts := &serviceOptions{
|
|
|
|
credentialSpec: credentialSpecOpt{
|
|
|
|
value: &swarm.CredentialSpec{
|
|
|
|
Config: "foo",
|
|
|
|
},
|
|
|
|
source: "config://foo",
|
|
|
|
},
|
|
|
|
configs: *configOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a service spec. we need to be sure to fill in the nullable
|
|
|
|
// fields, like the code expects
|
|
|
|
service := &swarm.ServiceSpec{
|
|
|
|
TaskTemplate: swarm.TaskSpec{
|
|
|
|
ContainerSpec: &swarm.ContainerSpec{
|
|
|
|
Privileges: &swarm.Privileges{
|
|
|
|
CredentialSpec: opts.credentialSpec.value,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up a function to use as the list function
|
2025-05-19 13:55:23 +02:00
|
|
|
var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) {
|
2019-03-28 14:06:06 -05:00
|
|
|
f := opts.Filters
|
|
|
|
|
|
|
|
// we're expecting the filter to have names "foo" and "bar"
|
|
|
|
names := f.Get("name")
|
|
|
|
assert.Equal(t, len(names), 2)
|
|
|
|
assert.Assert(t, is.Contains(names, "foo"))
|
|
|
|
assert.Assert(t, is.Contains(names, "bar"))
|
|
|
|
|
|
|
|
return []swarm.Config{
|
|
|
|
{
|
|
|
|
ID: "fooID",
|
|
|
|
Spec: swarm.ConfigSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
ID: "barID",
|
|
|
|
Spec: swarm.ConfigSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-09-09 22:27:44 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-03-28 14:06:06 -05:00
|
|
|
// now call setConfigs
|
2023-09-09 22:27:44 +00:00
|
|
|
err := setConfigs(ctx, fakeClient, service, opts)
|
2019-03-28 14:06:06 -05:00
|
|
|
// verify no error is returned
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
credSpecConfigValue := service.TaskTemplate.ContainerSpec.Privileges.CredentialSpec.Config
|
|
|
|
assert.Equal(t, credSpecConfigValue, "fooID")
|
|
|
|
|
|
|
|
configRefs := service.TaskTemplate.ContainerSpec.Configs
|
|
|
|
assert.Assert(t, is.Contains(configRefs, &swarm.ConfigReference{
|
|
|
|
ConfigID: "fooID",
|
|
|
|
ConfigName: "foo",
|
|
|
|
Runtime: &swarm.ConfigReferenceRuntimeTarget{},
|
|
|
|
}), "expected configRefs to contain foo config")
|
|
|
|
assert.Assert(t, is.Contains(configRefs, &swarm.ConfigReference{
|
|
|
|
ConfigID: "barID",
|
|
|
|
ConfigName: "bar",
|
|
|
|
File: &swarm.ConfigReferenceFileTarget{
|
|
|
|
Name: "bar",
|
|
|
|
// these are the default field values
|
|
|
|
UID: "0",
|
|
|
|
GID: "0",
|
2022-09-30 19:13:22 +02:00
|
|
|
Mode: 0o444,
|
2019-03-28 14:06:06 -05:00
|
|
|
},
|
|
|
|
}), "expected configRefs to contain bar config")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestSetConfigsOnlyCredSpec tests that even if a CredentialSpec is the only
|
|
|
|
// config needed, setConfigs still works
|
|
|
|
func TestSetConfigsOnlyCredSpec(t *testing.T) {
|
|
|
|
opts := &serviceOptions{
|
|
|
|
credentialSpec: credentialSpecOpt{
|
|
|
|
value: &swarm.CredentialSpec{
|
|
|
|
Config: "foo",
|
|
|
|
},
|
|
|
|
source: "config://foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
service := &swarm.ServiceSpec{
|
|
|
|
TaskTemplate: swarm.TaskSpec{
|
|
|
|
ContainerSpec: &swarm.ContainerSpec{
|
|
|
|
Privileges: &swarm.Privileges{
|
|
|
|
CredentialSpec: opts.credentialSpec.value,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up a function to use as the list function
|
2025-05-19 13:55:23 +02:00
|
|
|
var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) {
|
2019-03-28 14:06:06 -05:00
|
|
|
f := opts.Filters
|
|
|
|
|
|
|
|
names := f.Get("name")
|
|
|
|
assert.Equal(t, len(names), 1)
|
|
|
|
assert.Assert(t, is.Contains(names, "foo"))
|
|
|
|
|
|
|
|
return []swarm.Config{
|
|
|
|
{
|
|
|
|
ID: "fooID",
|
|
|
|
Spec: swarm.ConfigSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// now call setConfigs
|
2023-09-09 22:27:44 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
err := setConfigs(ctx, fakeClient, service, opts)
|
2019-03-28 14:06:06 -05:00
|
|
|
// verify no error is returned
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
credSpecConfigValue := service.TaskTemplate.ContainerSpec.Privileges.CredentialSpec.Config
|
|
|
|
assert.Equal(t, credSpecConfigValue, "fooID")
|
|
|
|
|
|
|
|
configRefs := service.TaskTemplate.ContainerSpec.Configs
|
|
|
|
assert.Assert(t, is.Contains(configRefs, &swarm.ConfigReference{
|
|
|
|
ConfigID: "fooID",
|
|
|
|
ConfigName: "foo",
|
|
|
|
Runtime: &swarm.ConfigReferenceRuntimeTarget{},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestSetConfigsOnlyConfigs verifies setConfigs when only configs (and not a
|
|
|
|
// CredentialSpec) is needed.
|
|
|
|
func TestSetConfigsOnlyConfigs(t *testing.T) {
|
2025-03-08 18:25:20 +01:00
|
|
|
configOpt := &swarmopts.ConfigOpt{}
|
|
|
|
assert.Check(t, configOpt.Set("bar"))
|
2019-03-28 14:06:06 -05:00
|
|
|
opts := &serviceOptions{
|
|
|
|
configs: *configOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
service := &swarm.ServiceSpec{
|
|
|
|
TaskTemplate: swarm.TaskSpec{
|
|
|
|
ContainerSpec: &swarm.ContainerSpec{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2025-05-19 13:55:23 +02:00
|
|
|
var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) {
|
2019-03-28 14:06:06 -05:00
|
|
|
f := opts.Filters
|
|
|
|
|
|
|
|
names := f.Get("name")
|
|
|
|
assert.Equal(t, len(names), 1)
|
|
|
|
assert.Assert(t, is.Contains(names, "bar"))
|
|
|
|
|
|
|
|
return []swarm.Config{
|
|
|
|
{
|
|
|
|
ID: "barID",
|
|
|
|
Spec: swarm.ConfigSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// now call setConfigs
|
2023-09-09 22:27:44 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
err := setConfigs(ctx, fakeClient, service, opts)
|
2019-03-28 14:06:06 -05:00
|
|
|
// verify no error is returned
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
configRefs := service.TaskTemplate.ContainerSpec.Configs
|
|
|
|
assert.Assert(t, is.Contains(configRefs, &swarm.ConfigReference{
|
|
|
|
ConfigID: "barID",
|
|
|
|
ConfigName: "bar",
|
|
|
|
File: &swarm.ConfigReferenceFileTarget{
|
|
|
|
Name: "bar",
|
|
|
|
// these are the default field values
|
|
|
|
UID: "0",
|
|
|
|
GID: "0",
|
2022-09-30 19:13:22 +02:00
|
|
|
Mode: 0o444,
|
2019-03-28 14:06:06 -05:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestSetConfigsNoConfigs checks that setConfigs works when there are no
|
|
|
|
// configs of any kind needed
|
|
|
|
func TestSetConfigsNoConfigs(t *testing.T) {
|
|
|
|
// add a credentialSpec that isn't a config
|
|
|
|
opts := &serviceOptions{
|
|
|
|
credentialSpec: credentialSpecOpt{
|
|
|
|
value: &swarm.CredentialSpec{
|
|
|
|
File: "foo",
|
|
|
|
},
|
|
|
|
source: "file://foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
service := &swarm.ServiceSpec{
|
|
|
|
TaskTemplate: swarm.TaskSpec{
|
|
|
|
ContainerSpec: &swarm.ContainerSpec{
|
|
|
|
Privileges: &swarm.Privileges{
|
|
|
|
CredentialSpec: opts.credentialSpec.value,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2025-05-19 13:55:23 +02:00
|
|
|
var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) {
|
2019-03-28 14:06:06 -05:00
|
|
|
// assert false -- we should never call this function
|
|
|
|
assert.Assert(t, false, "we should not be listing configs")
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2023-09-09 22:27:44 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
err := setConfigs(ctx, fakeClient, service, opts)
|
2019-03-28 14:06:06 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
// ensure that the value of the credentialspec has not changed
|
|
|
|
assert.Equal(t, service.TaskTemplate.ContainerSpec.Privileges.CredentialSpec.File, "foo")
|
|
|
|
assert.Equal(t, service.TaskTemplate.ContainerSpec.Privileges.CredentialSpec.Config, "")
|
|
|
|
}
|