MCPcopy Create free account
hub / github.com/docker/cli / TestTrustSignerRemoveErrors

Function TestTrustSignerRemoveErrors

cmd/docker-trust/trust/signer_remove_test.go:16–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestTrustSignerRemoveErrors(t *testing.T) {
17 testCases := []struct {
18 name string
19 args []string
20 expectedError string
21 }{
22 {
23 name: "not-enough-args-0",
24 expectedError: "requires at least 2 arguments",
25 },
26 {
27 name: "not-enough-args-1",
28 args: []string{"user"},
29 expectedError: "requires at least 2 arguments",
30 },
31 }
32 for _, tc := range testCases {
33 t.Run(tc.name, func(t *testing.T) {
34 cmd := newSignerRemoveCommand(
35 test.NewFakeCli(&fakeClient{}))
36 cmd.SetArgs(tc.args)
37 cmd.SetOut(io.Discard)
38 cmd.SetErr(io.Discard)
39 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
40 })
41 }
42 testCasesWithOutput := []struct {
43 name string
44 args []string
45 expectedError string
46 expectedErrOut string
47 }{
48 {
49 name: "not-an-image",
50 args: []string{"user", "notanimage"},
51 expectedError: "error removing signer from: notanimage",
52 expectedErrOut: "error retrieving signers for notanimage",
53 },
54 {
55 name: "sha-reference",
56 args: []string{"user", "870d292919d01a0af7e7f056271dc78792c05f55f49b9b9012b6d89725bd9abd"},
57 expectedError: "error removing signer from: 870d292919d01a0af7e7f056271dc78792c05f55f49b9b9012b6d89725bd9abd",
58 expectedErrOut: "invalid repository name",
59 },
60 {
61 name: "invalid-img-reference",
62 args: []string{"user", "ALPINE"},
63 expectedError: "error removing signer from: ALPINE",
64 expectedErrOut: "invalid reference format",
65 },
66 }
67 for _, tc := range testCasesWithOutput {
68 t.Run(tc.name, func(t *testing.T) {
69 cli := test.NewFakeCli(&fakeClient{})
70 cli.SetNotaryClient(notaryfake.GetOfflineNotaryRepository)
71 cmd := newSignerRemoveCommand(cli)
72 cmd.SetArgs(tc.args)
73 cmd.SetOut(io.Discard)

Callers

nothing calls this directly

Calls 9

SetNotaryClientMethod · 0.95
ErrBufferMethod · 0.95
newSignerRemoveCommandFunction · 0.85
SetArgsMethod · 0.80
ContainsMethod · 0.80
StringMethod · 0.65
SetOutMethod · 0.45
SetErrMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…