MCPcopy Create free account
hub / github.com/docker/secrets-engine / Test_RmCommand

Function Test_RmCommand

plugins/pass/commands/command_test.go:147–199  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func Test_RmCommand(t *testing.T) {
148 t.Parallel()
149 t.Run("ok (two secrets)", func(t *testing.T) {
150 mock := teststore.NewMockStore(teststore.WithStore(map[store.ID]store.Secret{
151 store.MustParseID("foo"): pass.NewPassValue([]byte("bar")),
152 store.MustParseID("baz"): pass.NewPassValue([]byte("0")),
153 }))
154 out, err := execute(t, RmCommand(), mock, "foo", "baz")
155 assert.NoError(t, err)
156 assert.Equal(t, "RM: baz\nRM: foo\n", out)
157 l, err := mock.GetAllMetadata(t.Context())
158 require.NoError(t, err)
159 assert.Empty(t, l)
160 })
161 t.Run("--all", func(t *testing.T) {
162 mock := teststore.NewMockStore(teststore.WithStore(map[store.ID]store.Secret{
163 store.MustParseID("foo"): pass.NewPassValue([]byte("bar")),
164 store.MustParseID("baz"): pass.NewPassValue([]byte("0")),
165 }))
166 out, err := execute(t, RmCommand(), mock, "--all")
167 assert.NoError(t, err)
168 assert.Equal(t, "RM: baz\nRM: foo\n", out)
169 l, err := mock.GetAllMetadata(t.Context())
170 require.NoError(t, err)
171 assert.Empty(t, l)
172 })
173 t.Run("store error", func(t *testing.T) {
174 errRemove := errors.New("remove error")
175 mock := teststore.NewMockStore(teststore.WithStoreDeleteErr(errRemove))
176 out, err := execute(t, RmCommand(), mock, "foo")
177 assert.ErrorIs(t, err, errRemove)
178 assert.Equal(t, "ERR: foo: remove error\nError: "+errRemove.Error()+"\n", out)
179 })
180 t.Run("invalid id", func(t *testing.T) {
181 mock := teststore.NewMockStore()
182 out, err := execute(t, RmCommand(), mock, "/foo")
183 errInvalidID := secrets.ErrInvalidID{ID: "/foo"}
184 assert.ErrorIs(t, err, errInvalidID)
185 assert.Equal(t, "Error: "+errInvalidID.Error()+"\n", out)
186 })
187 t.Run("cannot mix --all with explicit list", func(t *testing.T) {
188 mock := teststore.NewMockStore()
189 out, err := execute(t, RmCommand(), mock, "--all", "foo")
190 assert.ErrorContains(t, err, "either provide a secret name or use --all to remove all secrets")
191 assert.Equal(t, "Error: either provide a secret name or use --all to remove all secrets\n", out)
192 })
193 t.Run("no args or --all", func(t *testing.T) {
194 mock := teststore.NewMockStore()
195 out, err := execute(t, RmCommand(), mock)
196 assert.ErrorContains(t, err, "either provide a secret name or use --all to remove all secrets")
197 assert.Equal(t, "Error: either provide a secret name or use --all to remove all secrets\n", out)
198 })
199}
200
201func Test_GetCommand(t *testing.T) {
202 t.Parallel()

Callers

nothing calls this directly

Calls 6

GetAllMetadataMethod · 0.95
ErrorMethod · 0.95
executeFunction · 0.85
RmCommandFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected