MCPcopy Index your code
hub / github.com/docker/cli / TestConfigCreateWithLabels

Function TestConfigCreateWithLabels

cli/command/config/create_test.go:85–121  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func TestConfigCreateWithLabels(t *testing.T) {
86 expectedLabels := map[string]string{
87 "lbl1": "Label-foo",
88 "lbl2": "Label-bar",
89 }
90 const name = "config-with-labels"
91
92 data, err := os.ReadFile(filepath.Join("testdata", configDataFile))
93 assert.NilError(t, err)
94
95 expected := swarm.ConfigSpec{
96 Annotations: swarm.Annotations{
97 Name: name,
98 Labels: expectedLabels,
99 },
100 Data: data,
101 }
102
103 cli := test.NewFakeCli(&fakeClient{
104 configCreateFunc: func(_ context.Context, options client.ConfigCreateOptions) (client.ConfigCreateResult, error) {
105 if !reflect.DeepEqual(options.Spec, expected) {
106 return client.ConfigCreateResult{}, fmt.Errorf("expected %+v, got %+v", expected, options.Spec)
107 }
108
109 return client.ConfigCreateResult{
110 ID: "ID-" + options.Spec.Name,
111 }, nil
112 },
113 })
114
115 cmd := newConfigCreateCommand(cli)
116 cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
117 cmd.Flags().Set("label", "lbl1=Label-foo")
118 cmd.Flags().Set("label", "lbl2=Label-bar")
119 assert.NilError(t, cmd.Execute())
120 assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
121}
122
123func TestConfigCreateWithTemplatingDriver(t *testing.T) {
124 expectedDriver := &swarm.Driver{

Callers

nothing calls this directly

Calls 5

OutBufferMethod · 0.95
newConfigCreateCommandFunction · 0.85
SetArgsMethod · 0.80
StringMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…