MCPcopy
hub / github.com/smallstep/cli / TestInspectCertificateRequest

Function TestInspectCertificateRequest

command/certificate/inspect_test.go:93–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91`)
92
93func TestInspectCertificateRequest(t *testing.T) {
94 // This is just to get a simple CLI context
95 app := &cli.App{}
96 set := flag.NewFlagSet("contrive", 0)
97 _ = set.String("format", "", "")
98 ctx := cli.NewContext(app, set, nil)
99
100 csr, err := pemutil.ParseCertificateRequest(csrPEMData)
101 assert.FatalError(t, err)
102
103 type testCase struct {
104 format string
105 verify func(buf *bytes.Buffer)
106 }
107
108 tests := map[string]testCase{
109 "format text": {"text",
110 func(buf *bytes.Buffer) {
111 assert.HasPrefix(t, buf.String(), "Certificate Request:")
112 },
113 },
114 "format json": {"json",
115 func(buf *bytes.Buffer) {
116 var v interface{}
117 err := json.Unmarshal(buf.Bytes(), &v)
118 assert.NoError(t, err)
119 },
120 },
121 "format pem": {"pem",
122 func(buf *bytes.Buffer) {
123 assert.Equals(t, string(csrPEMData), buf.String())
124 },
125 },
126 }
127
128 for name, tc := range tests {
129 t.Run(name, func(t *testing.T) {
130 var buf bytes.Buffer
131 ctx.Set("format", tc.format)
132 err := inspectCertificateRequest(ctx, csr, &buf)
133 assert.NoError(t, err)
134 if err == nil {
135 tc.verify(&buf)
136 }
137 })
138 }
139
140}

Callers

nothing calls this directly

Calls 4

SetMethod · 0.80
StringMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…