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

Function TestTrustKeyLoadErrors

cmd/docker-trust/trust/key_load_test.go:23–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestTrustKeyLoadErrors(t *testing.T) {
24 noSuchFile := "stat iamnotakey: no such file or directory"
25 if runtime.GOOS == "windows" {
26 noSuchFile = "CreateFile iamnotakey: The system cannot find the file specified."
27 }
28 testCases := []struct {
29 name string
30 args []string
31 expectedError string
32 expectedOutput string
33 }{
34 {
35 name: "not-enough-args",
36 expectedError: "1 argument",
37 args: []string{},
38 expectedOutput: "",
39 },
40 {
41 name: "too-many-args",
42 args: []string{"iamnotakey", "alsonotakey"},
43 expectedError: "1 argument",
44 expectedOutput: "",
45 },
46 {
47 name: "not-a-key",
48 args: []string{"iamnotakey"},
49 expectedError: "refusing to load key from iamnotakey: " + noSuchFile,
50 expectedOutput: "Loading key from \"iamnotakey\"...\n",
51 },
52 {
53 name: "bad-key-name",
54 args: []string{"iamnotakey", "--name", "KEYNAME"},
55 expectedError: "key name \"KEYNAME\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character",
56 expectedOutput: "",
57 },
58 }
59 config.SetDir(t.TempDir())
60
61 for _, tc := range testCases {
62 cli := test.NewFakeCli(&fakeClient{})
63 cmd := newKeyLoadCommand(cli)
64 cmd.SetArgs(tc.args)
65 cmd.SetOut(io.Discard)
66 cmd.SetErr(io.Discard)
67 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
68 assert.Check(t, is.Contains(cli.OutBuffer().String(), tc.expectedOutput))
69 }
70}
71
72var rsaPrivKeyFixture = []byte(`-----BEGIN RSA PRIVATE KEY-----
73MIIEpAIBAAKCAQEAs7yVMzCw8CBZPoN+QLdx3ZzbVaHnouHIKu+ynX60IZ3stpbb

Callers

nothing calls this directly

Calls 7

OutBufferMethod · 0.95
newKeyLoadCommandFunction · 0.85
SetArgsMethod · 0.80
ContainsMethod · 0.80
StringMethod · 0.65
SetOutMethod · 0.45
SetErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…